0

i want to read text between two indices in the file usinf file i/o operations in c++. HOw ca i do it? for example, here is the text file:

1:
..
..
2:
..
..
3:
..
..
4:
in this text file i need to print only the lines between 2: and 3:. How could this be done?

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

You need to actually read every line, but you can ignore the lines at a specific "index" by simply not printing them.

0

Really? How is it that so many people these days are getting into projects without knowing the first thing about C++? Here, this program will read and print every line in a file:

#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    ifstream in("myfile.txt");

    if (in)
    {
        string line;

        while (getline(in, line))
        {
            cout << line << '\n';
        }
    }
}

I strongly recommend getting a book on C++ and reading it. Alternatively you can search Google for tutorials. This forum is best suited for helping with specific problems, not teaching you from scratch.

This topic has been dead for over six months. 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.