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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:36:59+00:00 2026-05-23T04:36:59+00:00

I am reading the book C++ Primer and at the file input output chapter

  • 0

I am reading the book C++ Primer and at the file input output chapter it uses:

ifstream infile(ifile.c_str());

to open a file whose name is in the string ifile.

I tried the code and it works perfectly even without c_str(). So what is the point of using it?

Should I use c_str() when I am trying to open a file from a command line argument? I mean which is the correct usage:

ifstream fin( argv[1] )

or

ifstream fin( argv[1].c_str() )
  • 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-23T04:37:00+00:00Added an answer on May 23, 2026 at 4:37 am

    The constructor for ifstream used to only take a const char * (which is what the c_str() method provides.

    I believe that there is a new constructor for it that takes a std::string in the upcoming standard, (edit) see this answer.

    It could also be specific to your implementation.

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

Sidebar

Related Questions

I'm reading a book, the Primer guide to C++. I think I got the
I have been reading the book of Windows via C/C++. In chapter 8, page
I am reading the book JavaScript-The Good Parts, in chapter 4.14 Curry, the book
Recently i'm reading the book Operating System Concepts Chapter VI about critical section problem,
While reading a book on C#, I have come across code that uses the
Recently, I was reading book about Erlang which has hot deployment feature. The deployment
Reading a book I have found the following statement: (Object) Behaviors answer either of
While reading a book about JavaScript I stumbled across an example: var names =
I'm reading the book 'Beginning F#', There's a short list for example code, to
I've been reading a book on the cocos2d framework for ios5 for a few

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.