CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//This is the code for my question in Discuss section.
//ERROR: [Error] no matching function for call to 'std::basic_ofstream<char>::open(std::string&)'
//I use "Dev - C++", maybe its because of the program that I use ???
//It works with no errors on Sololearn.
/* *SOLVED* */
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
string name;
name = "text.txt";
ofstream afile;
afile.open(name); //ERROR
//The code that works in Dev-C++:
//afile.open( name.c_str() );
afile.close();
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run