class and strings

I am trying to write a text file but I am getting an error with the "open.file" for the Lat_name() function.



#include<iostream>
#include<string>
#include <fstream>
#include <cstdlib>


using namespace std;

void Last_name();
void Firstname_Lastname();

int main()
{
Last_name();
Firstname_Lastname();
return 0;
}


void Last_name()
{
string filename = "Last name.txt";
string line;
fstream outfile;

outfile.open(Last_name); /* I am getting an error here */

if (outfile.fail())
{
cout << "\nThe file was not successfully opened"
<< "\n Please chelc that the file currently exists."
<< endl;
exit(1);
}

outfile.close();

return ;
}
closed account (E0p9LyTq)
PLEASE use code tags, it makes reading your code much easier.

You can go back and edit your previous post to add the code tags.
http://www.cplusplus.com/articles/jEywvCM9/

outfile.open(Last_name); /* I am getting an error here */

should be
outfile.open(filename);

You are trying to open a function, not a file.
Topic archived. No new replies allowed.