Is there a simpler method?
Code:vector<string> Size; char *s = strdup(Size[i].c_str()); long long num = _strtoi64(s, NULL, 10);
This is a discussion on Vector element to char* within the C++ Programming forums, part of the General Programming Boards category; Is there a simpler method? Code: vector<string> Size; char *s = strdup(Size[i].c_str()); long long num = _strtoi64(s, NULL, 10);...
Is there a simpler method?
Code:vector<string> Size; char *s = strdup(Size[i].c_str()); long long num = _strtoi64(s, NULL, 10);
Compiler MSVC++ 2010 with Code::Blocks.
If your standard library implementation conforms sufficiently to C++11, you could write:
Code:vector<string> Size; // ... long long num = stoll(Size[i]);
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
You don't need char* in the first place. _strtoi64 (which is bad function to use, btw) takes a const char*, because it doesn't change its parameters. Therefore, simply calling c_str() should suffice.
Also, to duplicate a string, all you need is to simply declare another string and assign the old one to it.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^