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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:39:57+00:00 2026-05-26T03:39:57+00:00

If I change myfile(input.txt) to myfile(file_name)…where file_name is passed to the function it does

  • 0

If I change myfile(“input.txt”) to myfile(file_name)…where file_name is passed to the function it does not work but gives the error no matching function call..which I’m guessing b.c. I’m not suppose to be passing a string to the constructor…if not this way..how?

void file_to_string(string file_name)
{
   string line;  
   ifstream myfile("input.txt");
   if(myfile.is_open())
   {
      while(myfile.good())
      {
         getline(myfile,line);
         cout << line;
      }
      myfile.close();
  }
  else
  {
      cout << "File : " << file_name << " : did not open" ;
  }

}

int main(int argc, char *argv[])
{
    file_to_string(argv[1]);
}
  • 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-26T03:39:58+00:00Added an answer on May 26, 2026 at 3:39 am

    Use the c_str() member of the std::string class:

    ifstream myfile(file_name.c_str());
    

    It returns a null-terminated const char * representation of the string in question, which is exactly what you need here.

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

Sidebar

Related Questions

change() function works and detects changes on form elements, but is there a way
jquery change function on dropdown is not working at my application and working at
See the code: var fs = require('fs'); var file = e:/myfile.txt; fs.stat(file, function(err, stat1)
I change schema.yml from time to time and execute: symfony propel:build-all-load but the lib/_model
I change some methods from $(selector).live('click', function(){}); to $(selector).on('click', function(){}); . At first it
My map function has to read a file for every input. That file doesn't
If File.SetAttributes(C:\\myFile.txt, FileAttributes.ReadOnly); sets a file as read only, how do I set it
Say I have a file, myfile.txt. It has a paragraph of text in it,
I made a icon overlay to my file, *.myfile , but the overlay size
SETLOCAL enableextensions enabledelayedexpansion :: change your Given/First name set MYSELF=Felipe set BOSS=Jon set MYFILE=Timesheet_%MYSELF%_FY10.11_Version_1.1.xls

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.