Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6888813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:04:29+00:00 2026-05-27T06:04:29+00:00

This project is in c++. I am trying to move along a textfile, and

  • 0

This project is in c++. I am trying to move along a textfile, and print each time a substr of 80 characters long on the screen. The next step would be to update the start position of x and then print again. My goal is to ‘slide’ over a txt. When I start the second stream operation I don’t get an error but there is no text outputted on the screen anymore.
Anyone who knows what i am doing wrong? Do i have to close the file before performing a new operation? Thanx

ifstream ifs("data.txt");
string line;
string subline;
int x=5;

while(getline(ifs,line)) {
    subline=line.substr(x,80);
    cout << subline;
}

system("pause");
system("cls");
x++;


//my issue!
while(getline(ifs,line)) {
    subline=line.substr(x,80);
    cout << subline;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:04:30+00:00Added an answer on May 27, 2026 at 6:04 am

    You’re reaching the end of the file and it’ll be setting the ‘eof‘ state bit (and removing the ‘good‘ state bit). That’ll mean basically all subsequent read operations fail.

    easy fix is to add after the x++:

    ifs.clear(); // Get rid of the 'eof' state bit
    ifs.seekg(0, ios_base::beg); // Go back to the beginning of the file
    
    • ifs.clear reference
    • ifs.seekg reference
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying for a long time to move this large project I'm working
I'm trying to move my project to CMake, and at the same time have
I am having trouble trying to put in data for this project I'm working
I'm trying to use proguard in a Maven project this is a obfuscate plugin,
I am trying to run a sample project from This site . Jboss starts
So the base project is this... I am trying to write a server application
This is my first android project so please help I am trying to create
I am trying to deserialize this JSON array into my android project. [{Name:Ban,Price:1},{Name:Banana,Price:1},{Name:chicken,Price:14},{Name:pizza,Price:16},{Name:slice,Price:1}] I
I'm trying include this barcode source code Stefanhafeneger - Barcode github.com to my project
I found this tutorial and am trying to implement it in my project http://www.androiddevblog.net/android/playing-audio-in-android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.