我需要一个C ++程序来获取.txt或.doc文件的输出?

时间:2015-03-08 15:13:41

标签: c++

对于Ex。假设我节省了几个。图21和42分别存储在int a和int b中。我想打开一个现有的或新的.txt或.doc并在其中打印21和42。这可能吗?

1 个答案:

答案 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;
}