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 6637809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:21:31+00:00 2026-05-25T23:21:31+00:00

All I need to do is a simple read from a file in the

  • 0

All I need to do is a simple read from a file in the same directory, but for some reason it refuses to work.

It works perfectly fine in this quick test one I made after I had problems, and outputs the number of entries in the text file.

#include <iostream>
using std::cout;
using std::cin;

#include <cstdio>

int main()
    {
    int a;
    int b = 0;
    freopen ("7.txt", "r", stdin);

    while (cin >> a)
        ++b;

    cin.clear();

    fclose (stdin);
    freopen ("7.txt", "r", stdin);

    cout << b << '\n';

    fclose (stdin);
}

EDIT: Wow I’m sorry to everyone who tried wrapping their heads around this. It was pretty late when I posted this, but I thought I finished. Apparently not. Now upon reopening my file to post the code in it, I realize that I moved everything into a folder before, but apparently when I tried to run the actual thing, it saved back outside of the folder, so it couldn’t open “7.txt”.

Problem solved I guess, sad waste of space seeing as how it wasn’t even complete O_o, sorry.

EDIT2: Okay now I’m confused. I had a temp account on this computer, but when I logged into this account to ask a different question, this one as I meant to post it the other night showed up. I wasn’t even on this computer while asking it. Not sure why it wasn’t posted like that if it was all ready to be though.

  • 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-25T23:21:31+00:00Added an answer on May 25, 2026 at 11:21 pm

    My best “guess” is that you are trying to re-read the same file. If this is the case then you could try this :

    std::ifstream file("7.txt");
    std::string line = "";
    while(std::getline(file, line))
    {
      //do something
    }
    //reset file pointer
    file.clear();
    file.seekg (0, std::ios::beg);
    //re-read file
    while(std::getline(file, line))
    {
      //do something else
    }   
    

    Please try and formulate better questions in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a simple terminal-based program that should, Read some text from
I need to write a simple program that records all the input from parallel
I need to read data from a text file where the field lengths and
So all I need is a simple function that sets it up (eating incoming
I've got a reasonably simple query (this time) that I need ALL the results
I have a simple table view which is editable. All I need the user
I think the question is pretty simple, do I need all the rest of
I'm writing a simple web crawler in Ruby and I need to fetch all
I have multiple threads who all need to write to the same Dictionary. I
I need to read from a dataset which is very large, highly interlinked, the

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.