C++ 中如何将一个文本文档的内容显示在屏幕上
来源:百度知道 编辑:UC知道 时间:2024/06/06 20:26:15
RT,例如C盘下一个“1.txt“的文件,如何将其内容输出到屏幕上?
希望哪位高手能写一下,谢谢。
希望哪位高手能写一下,谢谢。
//---------------------------------------------------------------------------
#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{
ifstream ifs("c:\\1.txt");
char str[300];
while (!ifs.eof())
{
ifs.getline(str,299);
cout<<str;
}
ifs.close();
return 0;
}
//---------------------------------------------------------------------------
1.直接用fopen就行。
#include <stdio.h>
int main()
{
FILE *pf;
char str[1000];
pf = fopen("F:/112.txt", "r");
if (!pf)
return -1;
while (fgets(str, 1000, pf))
&