Start New Discussion within our Software Development Community

Hi All,
I'm brand new to C++ and writing a program which asks for user input to open a text file then displays the text file using specific characters which parse the file. The files that I need to open are too large to display the entire contents and the top of the file is getting cut off. Does anyone have any ideas on how to display the entire contents of the file? THANKS!!
Here's my code:


using namespace std;

int main()
    string filename;
    cout << "Enter location and name of .txt file:  ";
    getline ( cin, filename);
    ifstream in1 (filename.c_str() );
    string str1, line1;
    while(getline(in1, line1))
    str1 += line1;
    string toFind = "#";
    string replaceWith = "\n";
    string toFind2 = "[";
    string replaceWith2 = "\n";
    string toFind3 = "{";
    string replaceWith3 = "\n";
    string toFind4 = "!!!!";
    string replaceWith4 = "\n";
     int pos;
     while ((pos = str1.find(toFind)) != string::npos)
     while ((pos = str1.find(toFind2)) != string::npos)
     while ((pos = str1.find(toFind3)) != string::npos)
     while ((pos = str1.find(toFind4)) != string::npos)

     cout << str1 << endl; 

     return 0;

You could just display a certain number of lines and when the user presses the down arrow key it displays more text

This article has been dead for over six months. Start a new discussion instead.