Wat is wrong with this code? i want to create a file. The name of the file is in a string variable.
using namespace std;
int main() { string naambestand="txt.txt"; ofstream bestand; bestand.open(naambestand); bestand.close(); cout<<naambestand; cin.get(); return 0; }
ofstream::open() can't take a string, try: bestand.open(naambestand.c_str());
Log in to post a comment.
Wat is wrong with this code? i want to create a file. The name of the file is
in a string variable.
include <iostream>
include <fstream>
include <string>
using namespace std;
int main()
{
string naambestand="txt.txt";
ofstream bestand;
bestand.open(naambestand);
bestand.close();
cout<<naambestand;
cin.get();
return 0;
}
ofstream::open() can't take a string, try: bestand.open(naambestand.c_str());