complier errors?

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

21int main()
22 {
23
24 double x1,x2,x3,x4,y1,y2,y3,y4;
25 ifstream data;
26 string fname;
27
28 do
29 {
30
31 cout<<"Enter data file: "<<endl;
32 cin>>fname;
33
34 data.open(fname.c_str);
35
36 }while(!data);
37
38 getline(data,string);
39 getline(data,string);


Thats the code and these are the errors I keep getting

line 34 error:no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> > ::open(<unknown type>)

line 38 error: expected primary-expression before')' token
line 39 error: expected primary-expression before')' token
c_str is a function. You need to call it. You do that by putting parenthesis after it:

 
data.open(fname.c_str());  // put paranthesis here 


EDIT:

also... getline(data,string);

The 2nd param you pass to getline is the variable you want to receive the line. 'string' is not a variable, it's a typename. You probably meant to do getline(data,fname); or something.
Last edited on
Thank you sooo much!
Topic archived. No new replies allowed.