带有文本文件的程序 [英] Program with text file

查看:81
本文介绍了带有文本文件的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个程序,该程序设计用于学生平均成绩计算,按姓名和平均成绩(降序),对学生的最佳和最差的检索(平均)对学生进行排序,将所选字符加倍或从中删除数据文件.在此程序中,我需要在下面使用该代码.该程序应使用文本文件中的数据.




I need to write a program that is designed for students grade point average calculation, sort students by name and grade point average (descending order), the best and worst student retrieval (on average), double or remove selected characters from a data file. In this program I need to use that code below. This program should use data from text file.




#include<stdio.h>
void main( )
{
FILE *in; /* file location*/
int ch;
if ((in=fopen("test","r"))!=NULL)
/*opens file*/
{
while((ch= getc(in))!=EOF)
putc(ch, stdout);

fclose(in);
}
else
printf("can't open the file");
}

推荐答案

或者您也可以使用输入流直接读取整数值,如下所示:

Or you could use an input stream and read integer values directly, like this:

#include <fstream>
#include <iostream>
int main()
{
  ifstream is("filename");
  int input;
  if (is >> input)
    std::cout << "Read " << input << '\n';
  else
    std::cout << "Couldn't read an integer\n";
}



祝你好运!



Good luck!


这篇关于带有文本文件的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆