如何清空std :: string?

0 c++ iostream

我的代码的这一部分在一个无限循环中运行并显示一个数字,但我需要在使用后清空该字符串,因为它在循环中运行,它保持相乘.(对不起我的英文,这不是我的母语)

text ---> text text ----> text text text

cartemap << "Carte: " << currentmap;  //cartemap is a std:string currentmap a integer'

MESSAGE1 = TTF_RenderText_Solid( font,  cartemap.str().c_str() , noir );

apply_surface( 70, 70, MESSAGE1, SCREEN );

SDL_FreeSurface(MESSAGE1);
Run Code Online (Sandbox Code Playgroud)

Joh*_*web 5

回答标题中的问题

打电话std::string::clear()来清除string:

mystring.clear();
Run Code Online (Sandbox Code Playgroud)

回答帖子中的代码

但看起来您需要在示例中std::ostringstream::str()清除ostringstream(或stringstream):

cartemap.str("");
Run Code Online (Sandbox Code Playgroud)