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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:37:45+00:00 2026-06-02T04:37:45+00:00

I happened to run across a code example for reading text from a file

  • 0

I happened to run across a code example for reading text from a file as follows:

int i; 
char *fileName = "text.txt"; 
ifstream fin(fileName); 

while (fin >> i)
{
do something;
}

This code actually opens and reads space-delimited text, but I don’t understand how it works. How does the file get opened without an “open” or “read” command? Is there a way to rewind back to the beginning of the file? I’m trying to create a dynamically allocated array, which I don’t know how to do until after I’ve counted through the file for the number of scores.

  • 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-06-02T04:37:47+00:00Added an answer on June 2, 2026 at 4:37 am

    How does the file get opened without an “open” or “read” command?

    The ifstream constructor will open the file.

    Is there a way to rewind back to the beginning of the file?

    Use seekg(). If the EOF has been reached then you need to call clear() before calling seekg().

    I’m trying to create a dynamically allocated array

    If permitted, you could use std::vector to store the text read which would avoid having to read the contents of the file twice.

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

Sidebar

Related Questions

I need to run a bat file using a java code. I did that
I have the following code which initiate the thread. int iNMHandleThread = 1; HANDLE
It never happened to me. In Visual Studio, I have a part of code
I'm trying to run two Django projects simultaneously. I happened to be using mod_wsgi,
I may have a corruption problem in Eclipse run configurations. This happened after I
I'm not sure why this happened, but when I downgrade grails from 1.4.0 to
i wanted to run a .bat file in windows task scheduler, so i opened
I getting bug: crash happened outside the Java Virtual Machine in native code .
I have some new strange Eclipse behavior from yesterday. When I want to run
I wrote a little PHP script below to demonstrate my question. Run the code

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.