文件打开 [英] File Open

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

问题描述

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

例如:


#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

推荐答案

如果你想用浏览器窗口做这个,那么你应该尝试使用VC ++ MFC / COM


Raghu
If u want to do this with browser window then you shuld try to use VC++ MFC/COM

Raghu


nope,我不想用浏览器来做,只想构建一个简单的.cpp然后运行。任何想法?
nope, i dont want to do it with browser, just want to construct a simple .cpp then run. any idea?


xiaolim,你了解了std :: string和std :: cin(以及一般的输入)。你要做的是询问用户(通过std :: cout),接受对带有std :: cin的字符串的响应,然后在指定要打开的文件时使用该字符串。
xiaolim, have you learned about std::string and std::cin (and input in general). What you would do is ask the user (through std::cout), take in the response to a string with std::cin, and then use the string when specifying which file to open.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆