大家教教我,打开指定文件,文件位置由键盘输入。(c++)

来源:百度知道 编辑:UC知道 时间:2024/05/17 06:47:14
在线急等
用c++写程序啊

#include <fstream>

using namespace std;

int main() {
ifstream infile;
string filepath;
cout << "file path: " << endl;
cin >> filepath;
infile.open(filepath.c_str());
if (infile.fail()) {
// error...
}
...
infile.close();
}

大概就是这个流程吧,如果我没理解错你的意思.

#include <iostream>
using namespace std;

void main()
{
FILE *fp;
char Fs[256];
char ff[256];
cin>>Fs;
if ( NULL == ( fp = fopen( Fs, "ab+" ) ) )
{
system("pause");
exit(1);
}
while ( fgets( ff, 100, fp ) )
{
cout<<ff;
}
cout<<"\n";
system("pause");

fclose( fp );
}

回答者:匿名 5-21 11:44

正解。

回答者:匿名 5-21 11:44
高人!

说清楚啊,是用C++打开文件?