#include <iostream> #include <fstream> using namespace std; int main() { char data[100]; ofstream outfile; // outfile.open("test.txt",ios::out|ios::in);文件打开模式可以省略,ofstream就是写对象 //test.txt如果不存在会自动创建 outfile.open("test.txt"); outfile << "hello c++"; cout << "writing something" << endl; cin.getline(data,100); outfile << data << endl; cin >> data; cin.ignore();//用来忽略指定字符 outfile << data << endl; outfile.close(); return 0; }
时间: 2024-10-13 21:35:14