C++ char string int 如何轉換 合併

合併:

string a = "Hello ";
string b = a +"World";

與int之間的轉換
//int to string
int scale = 7;
string a = std::to_string(scale);
//string to int
char input = "8";
int countMachine = input -'0'; // accept 0-9

與char之間的轉換

//string to char
string info = ".edu";
char *hostchar = new char[info.length() + 1];
strcpy(hostchar, info.c_str());
// char to string
stringstream ss;
string s;
char c = 'a';
ss << c;
ss >> s;



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章