Hi,
I need to read a file character by character and send it to cout at the same time.
I have used get(char) but cannot lose the newline character.
I'm quite new to C++ and havn't yet grasped the concept behind c-strings/strings.
Code so far..

    while(in.get(n)) {
        if (n=='\n') {
            in.ignore();
        }
        cout << n << endl;
        x++;
        if(x==longest) {
            x = 0;
            y++;
        }
    }

The first line prints ok but the rest have 1st character missing.

Need help.

Thanks.

Recommended Answers

All 2 Replies

in.ignore() is reading another character and ignoring it. Replace in.ignore(); with continue; to "ignore" the current character in n.

Replace in.ignore(); with continue; to "ignore" the current character in n.

That's definitely the way to go !! :)

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.