Uncertain with a piece of code

So im looking through some tutorials for SDL and i stumbled upon this piece of code, i more or less know what it is doing, but im just uncertain because some of the syntax is new, plus i find the precise answer online, could someone explain what each line is doing?:

std::stringstream timeText;

/*more code i decided to skip because it was unrelated*/

timeText.str( "" );
timeText << "Milliseconds since start time " << SDL_GetTicks() - startTime; 

timeText.str( "" );

That clears the contents (not the state) of the stringstream.

timeText << "Milliseconds since start time " << SDL_GetTicks() - startTime;

This inserts the "Milliseconds since start time" into the stringstream, and then it inserts SDL_GetTicks() - startTime into it. You should be familiar with iostreams (std::cin, std::cout, etc). They are similar to stringstreams in that you insert/extract the content you want using operator<< (or operator>>), however a stringstream simply stores the value for usage, unlike std::cout, which displays the output.

I am awful at explaining things, so read up on stringstreams here.


Here are two simple example usages of them:

Good luck!
Topic archived. No new replies allowed.