>>Google for 'ifstream' and 'ofstream'.
With the extraordinary numbers of bad examples I would hesitate to suggest this. Perhaps a direct link to a well known high quality example would be better. Or, because this is a relatively simple operation an example can be typed up in the post.
Code:
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
int main()
{
std::string filename;
std::cout << "Enter a file name to open: ";
if (std::getline(std::cin, filename)) {
std::ifstream in(filename.c_str());
if (!in.is_open()) {
std::cerr << "Error opening file for reading" << std::endl;
return EXIT_FAILURE;
}
// in can be used like cin now
}
return EXIT_SUCCESS;
}
Using that example a simple reference is all that is needed to understand what is happening and modify the code to open a file for writing.