Link to home
Start Free TrialLog in
Avatar of jewee
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<char,
   std::char_traits<char>, std::allocator<char> >&)'
Avatar of stefan73
stefan73
Flag of Germany image

Hi jewee,
> fileTimeout = atoi(tokenList[2].c_str());

Try
fileTimeout = atoi((tokenList[2]).c_str());


Cheers,
Stefan
ASKER CERTIFIED SOLUTION
Avatar of stefan73
stefan73
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jewee
jewee

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
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