注册 登录
编程论坛 C++教室

文件操作

jsj273062425 发布于 2008-05-31 11:24, 417 次点击
请教高手:
怎样对文件里的数对进行操作?
例如:abc.txt里有 12 23
要对它进行相乘操作!
谢谢
2 回复
#2
flyue2008-05-31 18:55
#include <stdio.h>

int main()
{
    int a = 0, b = 0;

    FILE *fp = fopen("abc.txt", "r");
    fscanf(fp, "%d%d", &a, &b);
    printf("%d\n", a * b);

    return 0;
}
#3
zzy8402082008-06-01 12:50
用C++如下:
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
  ifstream in("abc.txt");
  int a;
  while(in>>a)
       cout<<a<<endl;
 
  getchar();
  return 0;

}
1