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

  • Home
  • SEARCH
  • 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 31055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:32:40+00:00 2026-05-10T13:32:40+00:00

I want to open a file for reading, the C++ way. I need to

  • 0

I want to open a file for reading, the C++ way. I need to be able to do it for:

  • text files, which would involve some sort of read line function.

  • binary files, which would provide a way to read raw data into a char* buffer.

  • 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. 2026-05-10T13:32:41+00:00Added an answer on May 10, 2026 at 1:32 pm

    There are three ways to do this, depending on your needs. You could use the old-school C way and call fopen/fread/fclose, or you could use the C++ fstream facilities (ifstream/ofstream), or if you’re using MFC, use the CFile class, which provides functions to accomplish actual file operations.

    All of these are suitable for both text and binary, though none have a specific readline functionality. What you’d most likely do instead in that case is use the fstream classes (fstream.h) and use the stream operators (<< and >>) or the read function to read/write blocks of text:

    int nsize = 10; std::vector<char> somedata(nsize); ifstream myfile; myfile.open("<path to file>"); myfile.read(somedata.data(), nsize); myfile.close(); 

    Note that, if you’re using Visual Studio 2005 or higher, traditional fstream may not be available (there’s a new Microsoft implementation, which is slightly different, but accomplishes the same thing).

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

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer This might work for you: http://support.microsoft.com/kb/555070 May 11, 2026 at 10:10 am
  • added an answer No, because ascx controls don't represent a real URL that… May 11, 2026 at 10:10 am
  • added an answer The difference is which other style attributes you inherit. Of… May 11, 2026 at 10:10 am

Related Questions

I want to open a file for reading, the C++ way. I need to
I want to open a file dialog box in user control. I used using
Suppose I want to open a file in an existing Emacs session using su
I want to open a save file dialog, have the user enter a filename,
I want to open a folder window, in the appropriate file manager, from within
I want to add a file type extension to the Open Dialog of Excel
In php I have open a .php file and want to evaluate certain lines.
I want to open a TCP client socket in Python. Do I have to
I have a long URL with tons of parameters that I want to open
I have a little program that I want to make open automatically when my

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.