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

在线急等用c++写程序啊
2025-04-19 10:22:16
推荐回答(5个)
回答1:

#include

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();
}

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

回答2:

#include
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< }
cout<<"\n";
system("pause");

fclose( fp );
}

回答3:

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

正解。

回答4:

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

回答5:

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