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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:14:56+00:00 2026-05-20T14:14:56+00:00

What type must I make my file name to use it as an argument

  • 0

What type must I make my file name to use it as an argument to ifstream.open()?

int main(int argc, char *argv[]) {
    string x,y,file;

    string file = argv[1];
    ifstream in;
    in.open(file);
    in >> x;
    in >> y;
    ...

With this code, I get the following error:

main.cpp|20|error: no matching function for call to 'std::basic_ifstream<char,
     std::char_traits<char> >::open(std::string&)'|
gcc\mingw32\4.4.1\include\c++\fstream|525|note: candidates are: void std::basic_ifstream<_CharT,
     _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]|

UPDATE:

i get this error
enter image description here

  • 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-20T14:14:56+00:00Added an answer on May 20, 2026 at 2:14 pm

    The constructor takes a const char* (http://www.cplusplus.com/reference/iostream/ifstream/ifstream/) so you should do it like this:

    in.open(argv[1]);
    

    or if you really want to use the file string variable, then

    in.open(file.c_str());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: std::ifstream in(some_file.txt); std::string line; // must be outside ? while(getline(in,line)){ // how to
What I must do is open a file in binary mode that contains stored
I need to write a generic class where the type parameter must be something
GenoTipController must produce class according to the enum type. i have 3 class: _Company,_Muayene,_Radyoloji.
I want user to type some text in JTextField and it must match some
Visual Studio complains: Warning 1 The designer must create an instance of type 'RentalEase.CustomBindingNavForm'
Here is my try: @header(Content-type: text/html; charset=utf-8); @header(Location:/index.php); @header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1 @header(Expires:
Type.GetType(System.String) Is there a lookup for the aliases available somewhere? Type.GetType(string) returns null .
type(3,) returns the int type, while t = 3, type(t) returns the tuple type.
IDEs are wonderful for many things. But I dislike how they make me use

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.