标签:out etl asd 2.3 分享 use ret src 图片
1、字符串分割
1 int main() { 2 string s = "asdhj,sfkkjdsi,sdni"; 3 istringstream ss(s); 4 string temp; 5 while (getline(ss, temp, ‘,‘)) 6 cout << temp << endl; 7 string t = "a5151,sf79dsi,sd120i"; 8 ss.clear(); 9 ss.str(t); 10 while (getline(ss, temp, ‘,‘)) 11 cout << temp << endl; 12 system("pause"); 13 return 0; 14 }
2、类型转换
1 int main() { 2 string s = "123"; 3 istringstream iss(s); 4 int i; 5 iss >> i; 6 cout << i << endl; 7 s = "12.345"; 8 iss.clear(); 9 iss.str(s); 10 float f; 11 iss >> f; 12 cout << f << endl; 13 system("pause"); 14 return 0; 15 }
stringstream类型转换的时候,一直读到第一个不符合类型的字符为止。
1 int main() { 2 string s = "123.456"; 3 istringstream iss(s); 4 int i; 5 iss >> i; 6 cout << i << endl; 7 float f; 8 iss >> f; 9 cout << f << endl; 10 system("pause"); 11 return 0; 12 }
标签:out etl asd 2.3 分享 use ret src 图片
原文地址:https://www.cnblogs.com/Zzz-y/p/9015873.html