0

My code compiles but for some reason there is one error that comes up:

Error:Multiple markers at this line - Invalid arguments ' Candidates are: void open(const char *, enum std::_Ios_Openmode) ' - no 
matching function for call to 'std::basic_ifstream::open(std::__cxx11::string&)'

I cannot seem to figure out why this error is thrown.

Here's my code:

    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    int main(){
     int array_for_numbs[10];
     int numbers[9]={1,2,3,4,5,6,7,8,9};
     int counttarr[9]={0};
      ifstream fileinpt;
       int num, dgt;
        string txtfile;
        cout<<"enter the test file:";
         cin >> txtfile;
         fileinpt.open(txtfile);// this line is where the error pops up :(
          int i=0;
 while (!fileinpt.eof())
 {
      fileinpt >> array_for_numbs[i];
      i=i+1;
 }
fileinpt.close();
 for(int i = 0; i < 10; i++)
 {
      num=array_for_numbs[i];
      do
      {
          dgt=num%10;
          num=num/10;
      }while(num>0);
    for(int i = 0; i < 9; i++)
    {
          if(dgt==numbers[i])
          {
               counttarr[i]=counttarr[i]+1;
          }
      }
  }
    cout<<"Digit \t"<< "Count \t"<<"Frequency "<<endl;
   for(int i = 0; i < 9; i++)
 {
      float frq=(float)counttarr[i]/(float)100;
      cout<<(i+1)<<"\t"<< counttarr[i]<<"\t" <<frq<<endl;
 }
 system("pause");
 return 0;
 }

1 Answer 1

1

"open" function filename argument has char* datatype, however, you are trying to pass std::string type path. Open function is a C function which is not aware of std::string type.

You have to cast/convert std::string to char*

Use;

fileinpt.open(txtfile.c_str());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.