C++写文件,会从str.txt中读取内容写入到str2.txt中
#include <stdlib.h>
#include <fstream>
#include <string>
#include <iostream>
int main(int argc, char* argv[])
{
std::ifstream fIn("str.txt");
std::ofstream fOut("str2.txt");
if (!fIn)
{
std::cout << "Open input file faild." << std::endl;
}
if (!fOut)
{
std::cout << "Open output file faild." << std::endl;
}
std::string str;
while (std::getline(fIn, str))
{
std::cout << str << std::endl;
fOut << str << std::endl;
}
fIn.close();
fOut.close();
system("pause");
return 0;
}