+ 2
How can I turn intigers to strings and reverse?
Thanks to all! 🤗😃
2 Respuestas
+ 11
You can convert integer to string by using built-in function to_string or you can try by yourself.
Example:
#include <iostream> // std::cout
#include <algorithm> // std::reverse()
#include <cstring> // std::string
using namespace std;
string itos(int val){
string tmp;
while(0 < val){
tmp.push_back(val%10+48);
val /= 10;
}
reverse(begin(tmp), end(tmp));
return tmp;
}
int main() {
string temp = itos(420);
cout<<temp; // outputs 420
return 0;
}
+ 8
There is a function to_string.
Take a look here:
http://www.cplusplus.com/reference/string/to_string/