| Jeff Whittle (4) | |
|
I have declared a vector by "std::vector<char[20]> token;". I expect this to create an empty vector of tokens, each 20 characters long. When I then add an item to the vector with "token.push_back(" ");" the compiler complains: "error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'const char [2]' to 'const char (&)[20]'" I do not understand this. My aim is to create an entry so that I can then plug characters into it by something like token[iToken][iChar] = "X". | |
|
|
|
| James2250 (323) | |
|
A vector is not able to hold arrays like you are trying to do. I suggest you just use strings and limit the length of them instead if you always want them less than 20 characters. | |
|
|
|
| Jeff Whittle (4) | |
|
Thank you. I'll try that. I was using char because I am using atoi and atof later to parse some numbers from text, and I think they only work with char arrays. Is there some way of parsing from strings? | |
|
|
|
| chipp (519) | ||||
you can try this:
btw, it's not tested yet, but i think it will works... | ||||
|
|
||||
| Jeff Whittle (4) | |||
|
Thanks to both of you for getting me thinking. I have now found that I can do exactly what I wanted to do by using a structure (or class) when declaring the vector. The following works just fine.
| |||
|
|
|||