C++ :: Random Access Iterators

May 20, 2013

In this code:

vector<int> mydata(100);
mydata[2] = 999;

In statement 2 does that call the iterator to access the 3rd position and set its value to 999?

View 18 Replies


ADVERTISEMENT

C :: Updating Record In Random Access File

Nov 5, 2014

I have been searching through the forums and found a couple snippets of code and from that i came up with this. What i want to do is search for the specific movie code and then update the movie status from inactive to active (for argument sake).

Code:
#include <stdio.h>
#include <stdlib.h>

typedef struct SYSTEM_MOVIE{
int movie_code;
int movie_dur;
char movie_title[25];

[Code] ....

View 1 Replies View Related

C :: Search A File For Specif Data And Update It (random Access)

Nov 9, 2014

The file name is "movie.dat" and currently i was able to save data into the file in this order:

[movie_code] [movie_dur] [movie_title] [movie_rating] [movie_dir] [movie_genre] [movie_status]

[12345] [120] [Movie] [PG13] [Director] [Comedy] [Active]

I want to search for the "movie_code" and change the [movie_status] from Active to Inactive.

So lets say for example i have a movie code 12345 saved in my movie file. I want to change the value from "Active" to "Inactive"for argument sake.

This is the code i was trying to do it with:

Code:
FILE *movie_fp;
movie_fp = fopen("movie.dat", "r+b");
int m_code;
MOVIE movie_data;
printf("*** Welcome to the movie updater! ***

[Code].....

View 3 Replies View Related

C/C++ :: Getting Values For Iterators

Dec 25, 2014

I'm having problem getting the values for iterators. This code:

auto sum = inputVec.begin() + itLast;

gave this error: no match for 'operator+'

#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
int main(){
vector<int> inputVec;

[Code] .....

View 4 Replies View Related

C++ :: Stream Iterators And Buffers?

Feb 6, 2013

Do stream iterators, such as std::istreambuf_iterator<char>, read a chunk of bytes internally, or do they read the stream one byte at a time?

Because I am thinking to write a BufferedFile class which uses an std::vector<char>.

View 3 Replies View Related

C++ :: Checking Type With Iterators

Oct 13, 2013

Assuming I have a list of pointers to a generic type T:

#include <vector>
//...
list<T*> myList;

Now assuming I want to go on the list, and if T's type is matched to the type I'm looking for, then cast it to this type and do something. List shown here:

list<T*>:: const_iterator iter= myList.begin();
for(; iter!=myList.end(); ++iter){
if( typeid(*iter)==typeid(Something*)) //RUN-TIME ERROR
dynamic_cast<Something*>(*iter)->DoSomething();
}

how do I fix this run-time error?

View 1 Replies View Related

C++ :: Std Container Iterators - Category?

Jun 15, 2014

When using an iterator with a std container (list / vector etc) sometimes it's possible to modify the container (e.g. delete an item) yet still carry on using the iterator - whereas in other cases, modifying the container immediately invalidates any open iterators on it. Is there an easy way to know which containers fall into which category? (or does it vary from one compiler to another?)

View 2 Replies View Related

C++ :: Segmentation Fault With Vectors And Iterators?

Oct 8, 2014

I am working on very large code.

View 4 Replies View Related

C/C++ :: Segmentation Fault With Vectors And Iterators?

Oct 9, 2014

I am working on very large code. I got a segmentation fault when trying to use one cpp file and tried to locate the error using Valgrind

Since the code is very large, I will only post a short portion of it below. I think the problem may come because triann is a vector defined in the header class, so triann[tri] is causing problems?

void ADe::aNe(int v, set<int> &nei)
{
for(set<int>::iterator iter = vert2tri[v].begin(); iter != vert2tri[v].end(); iter++)
{

[Code].....

View 4 Replies View Related

C++ :: Custom (readonly) Container And Iterators?

Jul 5, 2012

I'm working on writing some classes around a ROM hardware addon card. The classes expose the data on the ROM as a container with iterators, much like a vector or a list.

The classes don't have any data themselves, since all the data is on the ROM.

I'm having some dillemma's as to how to approach/implement the classes. If you were to write somethign like this... Or were using something like this written by someone else.... How would you expect this to be done ?

1) Make all the member functions static, make a private constructor to prevent making instances. This works, but may look a bit weird...

Code:
for (auto it = RomTable::begin(); it != RomTable::end(); ++it)

2) expect users to make a (dummy) instance, then use it as a regular container. this might be a bit counter intuitive since the class has no datamembers.

3) create a single instance, expect users to use that everywhere. make the constructor inaccessible. Some C++ 'purists' might perceive this as global data and thus not a good solution ?

Additionally. Do I need to provide both a const_iterator and an iterator ? There's nothing to be modified, so I'm guessing an iterator isn't needed (?) Or will some STL stuff not work without an iterator ? I'm obviously not fussed about the STL functions that make changes to the container to not work (like sort, fill, swap...)

View 14 Replies View Related

C++ :: Custom STL Compatible Containers And Iterators?

Jul 18, 2012

So i made an STL compatible container.And to make this work I had to make my own iterator (derived from std::iterator).

What is the portable (if any) and "well behaved" thing to do in case of usage anomalies.such as iterating an iterator too far, or passing an invalid index to a operator[]

Looking at how VC++ does things in something like std::array or std::vector.

Code:

iterator_type& operator+=(difference_type offset)
{// increment by integer
#if _ITERATOR_DEBUG_LEVEL == 2
if (size < index + offset)
{// report error

[Code] .....

lots of names starting with underscores, so it's implementation specific. Is there even a "well behaved" thing to do ? Or is any such work always going to be compiler specific?

View 2 Replies View Related

C++ :: Graph Class - How To Provide Virtual Iterators

May 29, 2013

I have a 'Graph' class, which has derived classes for Adjacency Matrix and Adjacency List representations.

How do I provide iterators for traversing vertices and edges, when the iterator classes would have different implementations for the different derived classes ?

The following way is the only one I can think of, but seems quite cumbersome.

Code:
class Base {
public:
class BaseIterator {

};
virtual const BaseIterator& begin();
virtual const BaseIterator& end();

[Code] .....

Or is there a pattern for doing this that I'm not aware of ? Would composition be a better idea here compared to polymorphism ? I mean, I can think like..a Graph can 'have' several representation 'objects' within it.

All the involved classes are templates,not sure if that makes the situation different.

View 7 Replies View Related

C++ :: Vector Iterators Incompatible In Debug Mode

Jul 11, 2013

I get this error when i try to run this code for an inventory in debug mode in VS. But for some reason it works just fine in release mode.

void Push_Back_Item(Item *item){
for(int y = 0; y < InvSizeY; y ++)
for(int x = 0; x < InvSizeX; x ++){
auto Iter = ItemList.find(std::make_pair(x,y));
if(Iter != ItemList.end()){
item->SetDead(); // ERROR
}
}
}

This isnt the full code though but it still gives me the same error.

The only thing "item->SetDead()" does is to set a bool to true.

This is the map i get the iterator from
std::map<std::pair<int,int>,Item*> ItemList;

This have been bugging me for quite some time now.

View 4 Replies View Related

C++ :: Access Private Data Of Base Class Without Access Modifier

Sep 9, 2013

if we don't provide the acces modifiers for base class and we need to manipulate the private data of base class in derived class. Is there anyway to acces the private data members? Here's a coding example

class A {
private :
int a;
};
class B : public class A {
public :
void displayA() { cout<<a<<endl; }
};

how i can acces the a of base class A in derived class B without acces modifiers.

View 16 Replies View Related

C++ :: Make 10 Random Numbers Thus Making 10 Random Flips Of Coin?

Aug 31, 2013

I want to make 10 random numbers thus making 10 random flips of a coin. I am getting 10 tails or 10 heads!

Code: #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(int argc, const char * argv[])
{

[Code].....

View 4 Replies View Related

C++ :: Random Value At Random Time?

Dec 30, 2013

my motive is to get random variable at every start of program.so it does not show same sequence when it run again and again

int main()
{
srand( time ( NULL ) );
cout<<rand();
}

when i run this program in code::block the following program is opening with error in new tab called TIME.H

/*
* time.h
* This file has no copyright assigned and is placed in the Public Domain.
* This file is a part of the mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within the package.
*
* Date and time functions and types.
*
*/
#ifndef_TIME_H_
#define_TIME_H_

[Code]....

View 5 Replies View Related

C++ :: Why Are Random Values Not Very Random

Nov 26, 2014

I've been working on a little experiment, here is the source: [URL]

The problem that I keep running into is when I run the initPop and generate an individual object, the genome of the next individual is _exactly_ the same as the previous one... which confuses me... Shouldn't each individual be randomly different from the one that preceded it? What am I not right when it comes to generating random values?

View 8 Replies View Related

C++ :: Why Can't Access The Variable

Jul 17, 2014

Code:
#include <iostream>
using namespace std;
void f();
extern int x;
int main() {

[Code] .....

x is declared outside the functions and defined inside main(). Then why this code produces a compile error?

x is already declared so it can be used in f(); and when I call f(), x is already defined. Then why can't f() sets the value of x (in main) to 10?

View 3 Replies View Related

C/C++ :: How To Access XML Documents

Apr 9, 2012

this is the XML document i have:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<ConfigParams>
<Param Name="1">1857</Param>
<Param Name="2">10.31.225.163</Param>

[Code] ....

How to write a C++ code to access thing. (like we use JAXB in java)

View 1 Replies View Related

C++ :: How To Access File Properties

Jun 29, 2014

Is it possible to access file properties from c++ program? For example, user could drag file to program and then it displays a detailed information about file like date modified, size, type and etc..

View 1 Replies View Related

C :: How To Access Name And File Name Members

Sep 8, 2014

How to access the name and file name members on line 42 and 43?

Code:

typedef struct {
char * name;
char * filename;
} FILES;
FILES * files[256];
}

[code]...

How to access the name and filename from within function?

*files[count].name = chTmp;

View 9 Replies View Related

C++ ::  Access To Array By String Of Its Name

Jul 31, 2013

I have an array called abee1.

int abee1[4][3];

I have done some string function (like: "abee" + "1" ) and have "abee1" as string which is the same as abee1. How can I copy the data of abee1 into another array with same size, for example abeeTwo[4][3], using only the name of abbe1 as string ("abee1") not by abee1 directly.

View 4 Replies View Related

C++ :: Access Objects From Another Thread

Jun 25, 2013

I have the following code below. I am getting a memory access violation when accessing cmd->query_string in the loop function. The loop() function is running in another thread. The cmd object appears to be destroyed after calling the send_command function. How do I create an object on the heap and access the query_string.

std::list<my_command_message_que*> my_command_que;
void loop(){
if(my_command_que.size() > 0){
my_command_message_que * cmd = my_command_que.front();
std::cout << cmd->query_string;

[Code] ....

View 2 Replies View Related

C++ :: Access EXE Global Variables From DLL

Jun 25, 2013

On linux, I can compile DLLs (shared objects) as well as executables that use them. I can even access globals and classes that are defined in the EXE from the DLL, and vice versa, simply with the 'export' keyword. flawlessly.

The Problem: But on Windows (using MinGW), no matter what I do, I'm completely unable to access global variables which defined in the EXE, from the DLL. On Linux, this is no sweat, but what's Windows' problem?

I also need to extend classes in the dll with base class method definitions defined in the exe.

Ive heard that on Windows, you need to use declspec(dllimport) and declspec(dllexport). I can compile with CygWin+MinGW/g++4.5.3 as well as "Pure Windows" with MinGW/g++4.7.2 *without* the declspecs. So what's the decljunk for? Is this really just something for MSVC or other compilers?

Here's some Windows code to show what the problem is. The DLL's global variable is accessible to the EXE just fine, but the EXE's global variable is not accessible to the DLL - compilation complains it is an undefined reference.

main.cpp
#include "myLib.h"
#include <stdio.h>
int exe;

[Code].....

edit: I tried using --enable-runtime-pseudo-reloc --allow-shlib-undefined options when compiling the DLL and G++ complains that --allow-shlib-undefined is an unrecognized option.

View 1 Replies View Related

C++ ::  Why Can't Get Access To Private Function

Aug 11, 2014

I've written a simple class given below. I had set the values through setab() function but the add()function didn't work.

Compiler shows CPP/class.cpp|20|error: ‘int Calc::add()’ is private|

#include <iostream>
using namespace std;
class Calc

[Code]....

View 5 Replies View Related

C++ :: Access To SQL Server Without ODBC

Feb 21, 2013

I need to connect and manipulate a DB in SQL Server 2008, but need to have high performance too, so, I want to develop an class in C++ that connect direct to DBMS, in a low level, without using ADO, ODBC or OLEDB.

I found this API [URL] .... which proposes to do exactly what I want, but I need to develop it by myself.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved