0

okay i have a file with data orgainzed like this in a dat file to be read:

apple.0.0.end.

and i want it to be read by char until it sees "." then print that, then read again repeated until the end of the line. so i can show the data like this:

name? : apple
noun? (0 for yes; 1 for no): 0
eatable? (0 for yes; 1 for no): 0

can this be done? how?
and explain like im 5 years old for future reference.

Edited by CreatorZeus

3
Contributors
2
Replies
17
Views
3 Years
Discussion Span
Last Post by deceptikon
0

You can set the delimiter for getline().

Indeed, but only one delimiter. If the line doesn't end with '.', input will span multiple lines. A full solution would use getline from the file to read a whole line, then getline with '.' as the delimiter from a stringstream of that line:

string line;

while (getline(in, line)) {
    // Display the line header

    stringstream ss(line);
    string line_part;

    while (getline(ss, line_part, '.')) {
        // Display the line part
    }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.