企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
#include <fstream> #include <iostream> using namespace std; int main () { char data[100]; //写入数据 ofstream outfile; outfile.open("a.txt"); cout << "write name..." << endl; cin.getline(data,100);//获取输入方式一 outfile << data << endl; cout << "write age... " << endl; cin >> data;//获取输入方式二 cin.ignore(); outfile << data << endl; outfile.close(); //读取数据 ifstream infile; infile.open("a.txt"); infile >> data; cout << data; infile >> data; cout << data; infile.close(); return 0; }