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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:01:43+00:00 2026-06-08T03:01:43+00:00

all. A new project of mine involves reading names from a file, and I

  • 0

all. A new project of mine involves reading names from a file, and I realized, especially for somebody who likes to (attempt to, more like) makes games, reading/writing to store information is very useful. I looked into it and discovered the std library pulls through again. I subsequently realized that, at least for me, the libraries from ios, ios_base, iostream, fstream, etc etc, seem to be kind of complex.

I looked around, but am not quite sure why this specific approach does not work. It puzzles me because examples found online that seem to follow the library as they should – I will refer to one on cplusplus.com. Of interesting note is that one worked as expected, while another didn’t. Far as I know, that is.

My problem is, I can create a file using ofstream, but not ifstream nor fstream. The way I understand it, there constructors, which I was using (which I beleive is identical paramaters as you would pass to open – that is, the filename and flags) are identical except in that they have different default perameters – ostream has ios::out, istream has ifstream has ios::in, and fstream has ios::in | ios::out – both flags, which is logical since it is the combination of both classes. Note this is not a problem of WHERE the file is created, rather, but the fact of its creation. I know this by two reasons. First, when using ofstream the file appears in expected directory, but not at all with ifstream nor fstream. Second, using the is_open function, (specifically, testing the expressions “while (is_open)” , the console never closed (I test most new concepts in the console because, well, it is simple), but with the others it did. If it had, then it never would have ended, since it can never go out of scope and thus the destructor spells the end for the open file.

My second problem was with using gcount – mostly how to access it. No matter how I tried (std::gcount, file::gcount, fstream::gcount…) it never recognized what it was. I was a bit befuddled.

Now comes a bit off off-topic ness to the specific issue, but more into the general reason of why I encountered this problem to begin with, which is sort of a discussion but I think it could be beneficial thing to learn, unless somehow I am the only one with this problem.

Firstly, the tuturial I had read over (learncpp.com) goes over the seekp/seekg functions, and said that it moves a relative amount in BYTES. It occured to me this is generally the same as a char, but is it possible that this is different on a different system (i.e, if a char was 2 bytes, you could figure this out, and apply this to the file searching), or will it always go by character, essentially, anyway?

And my main wonder… how to really use these tools to do things. Let’s say I want to put a name on each line. I would be a bit unsure how to do that, – newline character perhaps? Or the other end, reading a name per line – how do you find the starting position of the next line? (my issue with gcount arrises because I figured you could use getline(), then gcount(), and voila, move that many characters… not sure if that works though)

Thanks.

  • 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-08T03:01:45+00:00Added an answer on June 8, 2026 at 3:01 am

    To answer just one of your questions: you can’t create a file with ifstream because, well, it doesn’t create files; it’s simply not intended to. This purpose of this class is to read data from existing files, and to open a file and read from it, it must exist first. Simple as that.

    As far as fstream goes, you could make a case that it would make sense for it to create a file if none exists, but in fact, that’s not what it does; the argument to fstream‘s constructor must be an existing file. If the named file doesn’t exist, a failure bit is set in the object, and no file is created.

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

Sidebar

Related Questions

I use two jQuery plugins on new project of mine: $(input[type=text].color).miniColors(); $(input[type=file], input[type=radio], input[type=checkbox],
I'm starting a new project. I familiar with TortoiseSVN, and all its downsides. Shall
I've copied all my category files & header includes to the new Xcode project,
All, I'm starting a new ASP.NET MVC project which requires some content management capabilities.
What I want: Update all new commits from server with my local repository in
I'm currently working on setting up a new project of mine and was wondering
A colleague of mine was implementing a new feature in a project we work
An upcoming project of mine is considering a design that involves (what I'm calling)
For a project of mine, I am writing some STL containers from scratch (I
Hello and Happy New Year all! While thinking about new project I decided to

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.