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

问题描述

您好,如果我想提示用户找到该文件并打开,我该怎么做?

例如:


#include < iostream>

#include< fstream>

使用命名空间std;


int main(){

ofstream myfile;

myfile.open(" example.txt");

myfile<< 将其写入文件。\ n;;

myfile.close();

返回0;

}


如果我想提示用户打开example.txt如果没有在代码中打开,我将如何对其进行编码,以便在运行此程序时,第一件事将要求用户选择文件位置并打开,然后继续执行诸如写入将其写入文件之类的过程。谢谢

hi there, if i want to prompt user to locate the file and open, how would i do it?
for example:

#include <iostream>
#include <fstream>
using namespace std;

int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}

if i want to prompt user to open "example.txt" not open within the code, how would i code it so that when this programe is run, the 1st thing will ask for user to select file location and open, then continue the process such as writing "Writing this to a file". thanks

推荐答案




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

09-15 23:19