I have a program that is supposed to ask for the name of a file from the user, but when I attempt to use the variable that the file's name is stored in, I get this hefty error message.
error: no matching function for call to 'std::basic_ofstream<char, std::char_traits<ch...'
I have tried to use a C-style string, but either 'std::cin' or 'std::ofstream outfile(filename)' gives me an error message no matter what. Could somebody please tell me what is going on? Here is the source code. It is not complete yet, but it should compile nonetheless.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <fstream>
#include <limits>
#include <string>
int main()
{
std::string filename;
std::cout << "Input the name of the file you want to create. ";
std::cin >> filename;
std::ofstream outfile(filename);
// stuff
outfile.close();
std::cout << "Press the 'Enter' key to close the program.";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return 0;
}