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


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.

Recommended Answers

All 2 Replies

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.