1
可能重複:
In C++, how do you clear a stringstream variable?更改可變文本
我有一個字符串,我想用我的循環來顯示一個問題。
我把它像這樣在我的循環:
//while {
std::stringstream s;
s << "Hello";
font_surface = TTF_RenderText_Solid(font,s.str().c_str(),font_color);
apply_surface(x,y,font_surface,screen);
s << "GoodBye";
if(font_surface = TTF_RenderText_Solid(font,s.str().c_str(),font_color);
apply_surface(bx,by,font_surface,screen);
//end loop }
我的問題是輸出第一顯示Hello
然後在它HelloGoodBye
的其他位置,我需要我添加Goodbye
之前清除內容所以我只能看到屏幕上的第二個位置。
那麼在將其更改爲Goodbye
之前,如何清除Hello
的信息?
這似乎是使用'的std :: string'會是一個更好的選擇。 'std :: string s =「Hello」;/*通話功能*/s =「再見」;/*調用函數* /' – chris
我被建議使用當前的方法,因爲我將添加變量到我的字符串輸出將保存整數。 – Sir
啊,我明白了。你可以使用's.str(「」);',然後。看到這個:http://stackoverflow.com/questions/20731/in-c-how-do-you-clear-a-stringstream-variable – chris