0

This part of my code runs in an infinite loop and shows a number, but I need to empty the string after the use because, since it run in a loop, its keep being multiplied. (Sorry for my english, it's not my native language)

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);
johnsyweb
  • 136,902
  • 23
  • 188
  • 247

3 Answers3

5

Answering the question in the title

Call std::string::clear() to clear a string:

mystring.clear();

Answering the code in the post

But it looks like you need std::ostringstream::str() to clear an ostringstream (or stringstream) in your example:

cartemap.str("");
johnsyweb
  • 136,902
  • 23
  • 188
  • 247
1

If cartemap is your string, try this:

cartemap.resize(0);

http://www.cplusplus.com/reference/string/string/resize/

benathon
  • 7,455
  • 2
  • 41
  • 70
1

AFAICT from your snippet, cartemap is not an std::string, but it's std::stringstream or similar. To empty a string stream, do

cartemap.str("");
Matteo Italia
  • 123,740
  • 17
  • 206
  • 299