请再帮我看一下这个关于文件读写的程序

来源:百度知道 编辑:UC知道 时间:2024/07/04 02:24:17
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void show()
{
string name;
int age;
int score;
cout<<name<<age<<score<<endl;
}
int main(int argc, char**argv[])
{
string name;
int age;
int score;
iostream fout("f.txt");
fout<<name<<age<<score<<endl;
ifstream fin("f.txt");
fin>>name>>age>>score;
show();
return 0;
}编译有一个错误,我不明白,请再指点一下,谢谢
谢谢您的提醒,我按照您说的改过了,编译没错了,可是输出的是乱码,您能再帮我看看吗?谢谢!

LZ的函数概念还没搞懂。
SHOW()里面的三个变量是局部变量,跟外面的三个全局变量没关系,输出没有初始化的变量肯定是乱码。
应该把show()定义为:
void show(string n, ing a, int s){
cout << n << a << s;
}

调用:
show(name, age, score);

首先,您提问的方法有问题,既然编译有错误,就应该把错误写出来,这是别人解决你的问题的非常重要的信息。

iostream fout("f.txt"); 这里是错误的,应该写成ofstream