-
vectors question
hello
this is probabley a simple probelm to overcome but i have spent ages trying to figure out what to do and have not got anywhere
i am reading in a file a line at a time e.g
while (! jppfile.eof() ) {
jppfile.getline (buffer,200);
cout << buffer ;
}
where jppfile is a stream, now this works great and i now want to store them (each line) in a vector; simple i thought:
vector <char[200]> instructions; //200 that is how long buffer is
i then proceede to push them onto the vector:
instructions.push_back(buffer);
But this is the error being given to me:
cannot convert from 'const char [200]' to 'char [200]'
I persumed that this is something to do with the fact that bufer is never actually 200 characters long, and the vector is expecting 200 characters so conflict is arising. Is there something obvious that i have missed or is there a solution to the problem that is a bit more complicated
sorry to bother people
cheers
:D
-
Your declaration is wrong, first if you want a vector of char array's (which is impposible although you could do char*'s) you should instead use the string type since you are already using vectors. so why not just include the string library change your loop to this:
Code:
vector<string> instructions;
string strTmp;
while(!jpgfile.eof())
{ getline(jgpfile,strTmp);
instructions.push_back(strTmp);
}
-
thanks alot but.......
thanks very much your way did work!!!!!!
howevr i was hoping to avoid the use of strings (not the end of the world if i have to though).
You said that there was a way to do it with pointers,
could you please tell me the signature that the vector would need to have it hold a number of pointers pointing to char arrays.
thanks alot:D :D :D
-
Lol that is kinda funny not to sound rude or mean, but a vector is a template type that means you create one of a type putting the type in the < > brackets when you declare it, ex:
Code:
vector<string> vstr;
vecotr<char*> vpsz;
-
thank you
brill just got it workin!!!1
did it the way u suggested using strings
thanks for all ur help
rxg00u
-
i'm hoping the two threads were a mistake, maybe a slow connection