对于Ex。假设我节省了几个。图21和42分别存储在int a和int b中。我想打开一个现有的或新的.txt或.doc并在其中打印21和42。这可能吗?
答案 0 :(得分:1)
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main () {
int a=21;
int b = 42;
ofstream myfile;
myfile.open ("example.txt");
myfile << a << "\n" << b;
myfile.close();
return 0;
}