-
fstream
what is wrong with this?
Code:
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin;
ofstream fout;
int main()
{
char* tname = 0;
cout << "Enter the name of the file to change :" << endl;
cin >> tname;
fout.open(tname);
if (! fout.is_open())
{
cout << "Error opening file";
return 1;
}
fout << "yo bob!";
fout.close();
return 0;
}
my app crash when i try to run it..?
-
Your not allocating space for your pointer...your just decalring a pointer. Either use new to create some space or don't use a pointer.
-
Use std::string:
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ofstream fout;
string tname;
cout << "Enter the name of the file to change :" << endl;
cin >> tname;
fout.open(tname.c_str());