输入输出格式.doc

上传人:人*** 文档编号:542875789 上传时间:2023-12-02 格式:DOC 页数:3 大小:37.01KB
返回 下载 相关 举报
输入输出格式.doc_第1页
第1页 / 共3页
输入输出格式.doc_第2页
第2页 / 共3页
输入输出格式.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《输入输出格式.doc》由会员分享,可在线阅读,更多相关《输入输出格式.doc(3页珍藏版)》请在金锄头文库上搜索。

1、关于输入输出的格式由于课程作业的需要,我们对程序作业的输入输出的格式有一定的要求,每个输入的数据都放在input.txt文件中,输出的数据都存在output.txt文件中。求两个数的和: 输入示例 输出示例input.txt output.txt2 3 5下面是一个在标准C+中求和的输入输出的例子:实现的算法#includeusing namespace std;int main()int a,b;ifstream fin(input.txt);ofstream fout(output.txt);finab;fouta+bendl;return 0;下面是一个在标准C中求和的输入输出的例子:实

2、现的算法:#include int main()int a, b;freopen(input.txt, r, stdin);freopen(output.txt, w, stdout);scanf(%d %d, &a, &b);printf(%d, a + b);return 0;(关于freopen函数及stdin、stdout的说明见附录。)然而在线评测系统出于安全因素的考虑,禁止了程序对文件IO方面的权限,在线测试系统中,我们只需将freopen(input.txt, r, stdin);freopen(output.txt, w, stdout);这两句注释掉即可。说明附录:FILE

3、*freopen( const char *path, const char *mode, FILE *stream );Reassign a file pointer.参数说明:pathPath of new filemodeType of access permittedstreamPointer to FILE structurefreopen is typically used to redirect the pre-opened files stdin, stdout, and stderr to files specified by the user. The new file a

4、ssociated with stream is opened with mode, which is a character string specifying the type of access requested for the file, as follows:rOpens for reading. If the file does not exist or cannot be found, the freopen call fails.wOpens an empty file for writing. If the given file exists, its contents a

5、re destroyed.aOpens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it does not exist.r+Opens for both reading and writing. (The file must exist.)w+Opens an empty file for both reading and writing. If the g

6、iven file exists, its contents are destroyed.stdin, stdout, stderrFILE *stdin;FILE *stdout;FILE *stderr;#include RemarksThese are standard streams for input, output, and error output.By default, standard input is read from the keyboard, while standard output and standard error are printed to the scr

7、een.The following stream pointers are available to access the standard streams:PointerStreamstdinStandard inputstdoutStandard outputstderrStandard errorThese pointers can be used as arguments to functions. Some functions, such as getchar and putchar, use stdin and stdout automatically.These pointers are constants, and cannot be assigned new values. The freopen function can be used to redirect the streams to disk files or to other devices. The operating system allows you to redirect a programs standard input and output at the command level.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号