Reading File with Custom Break

Hello,

I am trying to create my own breaks in a .txt file so that my program will stop reading the file when it encounters this break. It works, but it will still output the "*" (break character) before stopping. Is there a way to exclude the break character from being output when running the program? Here is the code snippet that opens the file, reads to the break, and outputs the data:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
   string text;

    ifstream hello ("C:/Hello.txt");

    while (!hello.eof() && text != "*")
    {
        getline(hello, text);
        cout << text << endl;
    }

    hello.close();


Thanks for any help.
Nevermind, I got it. :)

Just had to add an if statement to check the string before the cout operation. Not sure if anyone will ever need to know this, but here is the code that works:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
   string text;

    ifstream hello ("C:/Hello.txt");

    while (!hello.eof() && text != "*")
    {
        getline(hello, text);
        if(text != "*")
        {
            cout << text << endl;
        }

    }

    hello.close();
Topic archived. No new replies allowed.