作者:mobiledu2402851377 | 2023-09-03 09:48
1> Martin York..:
读
#include
int main()
{
std::ifstream inputFile("MyFileName") // Opens a File.
int x;
inputFile >> x; // Reads an integer from a file.
std::string word;
inputFile >> word; // Reads a space separated word from a file.
double y;
inputFile >> y; // Reads a floating point number from the file.
// etc..
} // File AutoMagically closed by going out of scope.
写作
#include
int main()
{
std::ofstream inputFile("MyFileName") // Opens a File.
int x = 5;
inputFile << x << " "; // Writes an integer to a file then a space.
inputFile << 5 << " "; // Same Again.
std::string word("This is a line");
inputFile << word << "\n"; // Writes a string to a file followed by a newline
// Notice the difference between reading and
// writing a string.
inputFile << "Write a string constant to a file\n";
double y = 15.4;
inputFile << y << ":"; // Writes a floating point number
// to the file followed by ":".
// etc..
} // File AutoMagically closed by going out of scope.
2> Johannes Sch..:
一次全部
{
std::ifstream in("foo.txt"); /* opens for reading */
std::ofstream out("bar.txt"); /* opens for writing */
out << in.rdbuf(); /* streams in into out. writing and reading */
} /* closes automatically */