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?

Recommended Answers

All 3 Replies

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

how can i do that? can u tel me the keywords for doing them?

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.

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.