標題:
清空 stringstream
[打印本頁]
作者:
陳品肇
時間:
2019-7-20 12:56
標題:
清空 stringstream
ss.str("");
ss.clear();
[attach]6851[/attach]
#include<iostream>
#include<sstream>
#include<cstdlib>
using namespace std;
int main()
{
stringstream ss;
string str1="123",str2="456",str3,str4;
ss<<str1;
cout<<"ss: "<<ss.str()<<endl;
ss>>str3;
cout<<"str3: "<<str3<<endl;
ss.str("");
ss.clear();
ss<<str2;
cout<<"ss: "<<ss.str()<<endl;
ss>>str4;
cout<<"str4: "<<str4<<endl;
system("pause");
return 0;
}
複製代碼
作者:
湯郡一
時間:
2019-7-20 15:06
#include<iostream>
#include<sstream>
#include<cstdlib>
using namespace std;
int main()
{
stringstream ss;
string str1="123",str2="456",str3,str4;
ss<<str1;
cout<<"ss: "<<ss.str()<<endl;
ss>>str3;
cout<<"str3: "<<str3<<endl;
ss.str("");
ss.clear();
ss<<str2;
cout<<"ss: "<<ss.str()<<endl;
ss>>str4;
cout<<"str4: "<<str4<<endl;
system("pause");
return 0;
}
複製代碼
作者:
曲書辰
時間:
2019-7-20 15:06
#include<iostream>
#include<sstream>
#include<cstdlib>
using namespace std;
int main()
{
stringstream a;
string b="123",c="456",d,e;
a<<b;
cout<<a.str()<<endl;
a>>d;
cout<<d<<endl;
a.str("");
a.clear();
a<<c;
cout<<a.str()<<endl;
ss>>e;
cout<<e<<endl;
system("pause");
return 0;
}
複製代碼
作者:
吳孟書
時間:
2019-7-20 15:07
#include<iostream>
#include<cstdlib>
#include<sstream>
using namespace std;
int main()
{
stringstream ss;
string str1="123",str2="456",str3,str4;
ss<<str1;
cout<<"ss: "<<ss.str()<<endl;
ss>>str3;
cout<<"str3: "<<str3<<endl;
ss.str("");
ss.clear();
ss<<str2;
cout<<"ss: "<<ss.str()<<endl;
ss>>str4;
cout<<"str4: "<<str4<<endl;
system("pause");
return 0;
}
複製代碼
作者:
洪寬瀧
時間:
2019-7-20 15:08
#include<iostream>
#include<cstdlib>
#include<sstream>
using namespace std;
int main()
{
stringstream ss;
string str1="un",str2="unc",str3,str4;
ss<<str1;
cout<<"ss:"<<ss.str()<<endl;
ss>>str3;
cout<<"str3: "<<str3<<endl;
ss.str("");
ss.clear();
ss<<str2;
cout<<"ss:"<<ss.str()<<endl;
ss>>str4;
cout<<"str3: "<<str3<<endl;
system("pause");
return 0;
}
複製代碼
作者:
王瑞喻
時間:
2019-7-20 15:09
#include<iostream>
#include<sstream>
#include<cstdlib>
using namespace std;
int main()
{
stringstream ss;
string str1="123",str2="456",str3,str4;
ss<<str1;
cout<<"ss:"<<ss.str()<<endl;
ss>>str3;
cout<<"str3: "<<str3<<endl;
ss.str("");
ss.clear();
ss<<str2;
cout<<"ss: "<<ss.str()<<endl;
ss>>str4;
cout<<"str4: "<<str4<<endl;
system("pause");
return 0;
}
複製代碼
作者:
吳孟修
時間:
2019-7-20 15:14
#include<iostream>
#include<sstream>
#include<cstdlib>
using namespace std;
int main()
{
stringstream ss;
string str1="123",str2="456",str3,str4;
ss<<str1;
cout<<"ss: "<<ss.str()<<endl;
ss>>str3;
cout<<"str3: "<<str3<<endl;
ss.str("");
ss.clear();
ss<<str2;
cout<<"ss: "<<ss.str()<<endl;
ss>>str4;
cout<<"str4: "<<str4<<endl;
system("pause");
return 0;
}
複製代碼
作者:
田宇任
時間:
2019-7-20 15:15
#include<iostream>
#include<sstream>
#include<cstdlib>
using namespace std;
int main()
{
stringstream king;
string str1="abc",str2="def",str3,str4;
king<<str1;
cout<<"king: "<<king.str()<<endl;
king>>str3;
cout<<"str3: "<<str3<<endl;
king.str("");
king.clear();
king<<str2;
cout<<"king: "<<king.str()<<endl;
king>>str4;
cout<<"str4: "<<str4<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2