jewee
asked on
Question re: vectors
I am trying to set a value from a vector, convert it using atoi then saving it to an int:
std::vector<string> tokenList(3);
fileTimeout = atoi(tokenList[2].c_str()) ;
I get an error with and without the c_str:
testThis.cpp:29: no matching function for call to `atoi(std::basic_string<ch ar,
std::char_traits<char>, std::allocator<char> >&)'
std::vector<string> tokenList(3);
fileTimeout = atoi(tokenList[2].c_str())
I get an error with and without the c_str:
testThis.cpp:29: no matching function for call to `atoi(std::basic_string<ch
std::char_traits<char>, std::allocator<char> >&)'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Uggh. Unbelievable. Thanks! One more quick question. I am trying to set another token:
char fileDir[256];
fileDir = tokenList[2];
incompatible types in assignment
char fileDir[256];
fileDir = tokenList[2];
incompatible types in assignment
jewee,
> fileDir = tokenList[2];
Try if you can use a string instead of your char array.
If not, you need strcpy() for the c_str():
#include <strings.h>
strcpy(fileDir,tokenList[2 ].c_str()) ;
...but that's C-style code. There is no check for buffer overflows, for example.
Stefan
> fileDir = tokenList[2];
Try if you can use a string instead of your char array.
If not, you need strcpy() for the c_str():
#include <strings.h>
strcpy(fileDir,tokenList[2
...but that's C-style code. There is no check for buffer overflows, for example.
Stefan
> fileTimeout = atoi(tokenList[2].c_str())
Try
fileTimeout = atoi((tokenList[2]).c_str(
Cheers,
Stefan