第10六章,向txt文件中写入数据(C++)

第十六章,向txt文件中写入数据(C++)

#include <iostream>
#include <fstream>

int main(int argc, char** argv) {

	//app是追加的意思,append
	//盘符后面一定是双斜杠  \\ 
	//没有这个文件,会自动创建 
	std::ofstream outfile("e:\\123.txt",std::ios::app);
	
	if(outfile.is_open()){
		outfile<<"ccccc";
		//outfile<<"ccccc"<<"\n";会换行 
	}else{
		std::cout<<"没有写入成功!"<<std::endl; 
	}
		std::cout<<"写入成功!"<<std::endl; 
	
	return 0;
}
调试截图

第10六章,向txt文件中写入数据(C++)