Integer to String

So, I've managed to do this far and almost, almost done except for this one problem.
The output should be -- CAR = Toyota but instead I got this CAR = (2,3).
The output should be the type of the CAR in string, not some numbers. But I can't seems to figure out how to do this because if I change the variable x,y in the class CAR to string, it will result in an error.

How to do this?
Last edited on
Hmm, I know about to_string(), but that never seems to work for me. If you could make it a char, than I can help you. _ttoi() converts an integer to a char. If you were to use it, here is an example:

1
2
3
4
5
int a = 5;
char t1[];
char *t = &t1;

_ttoi(t);


Know that _ttoi is part of <tchar.h>, so remember to include that. Also, since it is <tchar.h>, it works for TCHARs too. But, it does work with regular chars.
Yes, how can I change the int to char instead?

I tried to use the the _ttoi() but there were several errors.



error: 't' is not a type|
|error: ISO C++ forbids declaration of 'atoi' with no type [-fpermissive]|
|error: cannot convert 'char (*)[0]' to 'char*' in initialization|
||=== Build finished: 3 errors, 1 warnings (0 minutes, 0 seconds) ===|

_ttoi() is only available on windows and it maps to atoi() or wtoi() depeding if UNICODE is enabled or not.

A portable and C++ native solution could be this:
1
2
3
4
5
6
7
#include <sstream>
#include <string>

int a = 10;
std::stringstream ss;
ss << a;
std::string str = ss.str();
C++11:

1
2
3
4
#include <string>

int x = 72;
std::string s = std::to_string( 72 );
Topic archived. No new replies allowed.