方法一:
#include<fstream>//ifstream流类在fstream中定义了
#include<iostream>
using namespace std;
int main(void)
{
ifstream cin("in.txt");
int a, b;
while(cin>>a>>b)//***
{
cout<<a + b<<endl;
}
return 0;
}
/*
cin默认的对象是键盘设备,cout默认的对象是屏幕设备,
只是现在输入对象cin被设为“in.txt”文件了,程序运行时,会自动从in.txt中读入数据,
注意:cin在读入数据时会忽略空格和回车。
*/
方法二:
while(scanf("%d%d", &A, &B) != EOF)
{
......
}
方法三:
//NYOJ算菜价;
#include<stdio.h>
#include<stdlib.h>
struct cost{
char name[100];
double qt;
double price;
}c;
int main()
{
freopen("in.txt","r",stdin);
double s=