loading data from a text file

hey guys,
hope you guys could help me.
i need to load data from a text file
i was able to load data separated by commas "," using this code:

        stringstream (loaded.substr(0,loaded.find(","))) >> temp;
        player1_turn = temp; //assigns the data to variable player1_turn
        loaded = loaded.substr(loaded.find(",")+1,loaded.length());

but i don't understand what this code does or how to modify it to read data after a string.
for example the data in the file is such=

p1HIT:1,3p1MISS:4,4 //endl

i want to extract the numbers for use and discard the strings and separators.

thanks in advance for any help!.
Consider std::istream.getline(char* c, std::streamsize n, char delimitor).


Anytime the documentation reads "extracts" it means that the character no longer is in the input stream.
thanks for the reply
but what does the code i used do exactly?

and can you please give an example of how getline is used to get data and assign it to a variable?
What your code does is simply to:

-Assign temp the content of loaded. ie: from the first character in the string to the first comma(because, find() returns the position of where the first comma was found)
-the it assigns player1_turn the value of temp
-Then it also assigns loaded, what. Loaded contains from the character after the first comma, to the end of the string.

great explanation aceix!
thanks a lot ill try to go from there to solve my issue

though if i could get a tip on the best way to read from a file with the following content it would be immensely appreciated=


i was able to read and load all the content in the first line, my problem starts from the second line onwards.
Topic archived. No new replies allowed.