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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:07:53+00:00 2026-05-26T09:07:53+00:00

I have some text files in a folder named foo1, foo2,…,foo5. I tried to

  • 0

I have some text files in a folder named foo1, foo2,…,foo5. I tried to write a C++ program
to print out the contents of the files but the compiler is giving an error.
Here is the program.

int main(int argc, char *argv[])
{

  string common="foo";

  for(int count=1;count<=5;++count)
  {
  //Convert count to an string.
  stringstream ss;
  ss<<count;
  string numstring=ss.str();

  string filename=common+numstring;
  ifstream infile(filename); 
  string line;

  //Print out the lines from the file.
   while(getline(infile,line))
     {
       cout<<line<<endl;

     }
  }

  return 0;
}

The compiler is giving an error like

g++ -Wall c++.cpp
c++.cpp: In function ‘int main(int, char**)’:
c++.cpp:26: error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::string&)’
/usr/include/c++/4.4/fstream:454: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/fstream:440: note:                 std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/iosfwd:81: note:                 std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)

Can someone help me out with this? The output of the program should be what I would get if I typed cat foo* at the terminal.

  • 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-26T09:07:54+00:00Added an answer on May 26, 2026 at 9:07 am

    Replace:

    ifstream infile(filename);
    

    with

    ifstream infile(filename.c_str());
    

    The error message that you posted shows you this. fstream is a typedef for basic_fstream<>. Your error message says, in essence, that there is no fstream constructor that takes a string&, but there is one that takes a char*.

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

Sidebar

Related Questions

I have a folder named Test . I have some .xls files and .txt
I've been trying to deal with some delimited text files that have non standard
I have some xml files that contain text, which are displayed on my website.
I have two files (f1 and f2) containing some text (or binary data). How
I have some html files that I want to convert to text. I have
I have to import some UTF-8 encoded text-file into my C++Builder 5 program. Are
I have one folder named test located at www.mydomain.com/abc/files/test. I need to change the
I have some *.hbm.xml files that are placed in the same folder at the
I'm trying to do this: cmd.exe /C C:\Program Files\Somewhere\SomeProgram.exe > C:\temp\Folder Containing Spaces\SomeProgram.out However,
I have text file with some text information and i need to split this

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.