simple saving to a text
i want to be able to choose what the file name that i can save to.
heres the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// basic file operations
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int sup[1] = {2200};
char filename[1];
int main () {
ofstream myfile;
cout << "what file name should used for this : " ;
cin >> filename[0];
myfile.open (filename[0].txt);
myfile << sup[0];
myfile.close();
return 0;
}
|
please help me
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// basic file operations
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int sup[1] = {2200};
string filename; // Note
int main () {
ofstream myfile;
cout << "what file name should used for this : " ;
cin >> filename; // Note
myfile.open (filename); // Note
myfile << sup[0];
myfile.close();
return 0;
}
|
thanks but i have this effor
15 E:\test v2\Untitled1.cpp no matching function for call to `std::basic_ofstream<char, std::char_traits<char> >::open(std::string&)'
This myfile.open (filename.c_str());
should solve the problem
thanks alot :),
can you just quickly explain what the "c.str()" does so i dont make the same mistake again :)
Topic archived. No new replies allowed.