cplusplus.com
C++ : Forum : Beginners : How to convert char to string
 
cplusplus.com
Information
Documentation
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs


post How to convert char to string

tnjones (38)
Hello,
I have a problem where I need to convert a char to a string and then a string to an int. Any help will be greatly thankful!!!

Thanks in Advance
Umz (205)
Have you tried anything yourself? You should start there... when a problem with what you've done comes up post your code and we'll help you through the issues
Cerburos (45)
I dont know if this is what you need

typecasting

http://www.cprogramming.com/tutorial/lesson11.html
Repentinus (31)
Char to string:
1
2
3
4
5
6
7
#include <sstream>
#include <string>
stringstream ss;
string s;
char c = 'a';
ss << c;
ss >> s;


String to int:
1
2
3
4
5
6
7
#include <sstream>
#include <string>
stringstream ss;
string s;
int n = 1;
ss << n;
ss >> s;
Last edited on
Cerburos (45)
Repentinus, Thanks for that reply. It tells a noob like me everything I need to know to use it. Thank you. Now I have a piece of code I can try out, experiment with, and learn from.
Zaita (2292)
I would've thought:
string mystring = string(char);
was sufficient.
Topic archived. No new replies allowed.