Monday, August 28, 2006

C++ note: int to string

import <string>
import <sstream>

using namespace std;

int main() {
...string s; a=1;
...stringstream ss; << a;
ss >> s;

also, use atoi or strtol for string to int (cstdlib).
use s = c to assign directly from C string to string, and use s.c_str() to get c string from string

No comments: