문제

To convert an integer to base 10 char*

std::itoa(ConCounter, ID, 10);

ConCounter is an integer, ID is a char*, and 10 is the base

It says that iota is not a member of std and without std it's not declared. I know it's a nonstandard function but I included all the libraries for it and it still doesn't see it.

What is a way to do the above? Any quick one liners? I've tried the following;

std::to_string //it's not declared for me when using mingw, it doesn't exist.
snprintf/sprintf //should work but it gives me the "invalid conversion from 'int' to 'char *'"    error
std::stoi //has same problem as iota
도움이 되었습니까?

해결책

I recommend using roybatty's answer, but I think sprintf should work too. I think when you used it you forgot the format string. It should be:

char buf[16];
std::snprintf(buf, sizeof(buf), "%d", integer);

다른 팁

Try this:

#include <sstream>

int i = // your number
std::ostringstream digit;
digit<<i;
std::string numberString(digit.str());

There is also "strtol" function : http://www.cplusplus.com/reference/cstdlib/strtol/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top