C++文件选择窗口
C++ File Selection Window
案例:我有几个文本文件,我需要有一个界面来选择它们到我的程序中。这是我写的代码
using namespace std;
vector<string> strings;
ifstream file("TestingRead.txt");
std::string str;
string myArray[5];
while (std::getline(file, str, ','))
{
cout << str << "n";
for (int i = 0; i <= 4; i++) {
myArray[i] = str;
}
strings.push_back(str);
}
请看一下:ifstream文件("TestingRead.txt"(;无论如何要替换硬代码方法吗?可能是文件选择器窗口?我的操作系统在 Linux 上运行
你应该看看一个GUI库,比如Gtk+、Qt、wxWidget等。例如,GtkFileChooserDialog
是你想要的 Gtk+ 中。
如果只需要打开文件一次,则编写代码和仅使用命令行参数可能会更容易:
#include <fstream>
#include <iostream>
int main (int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Provide filepath: ./my_program file_name" << std::endl;
return 1;
}
const std::string file_to_open (argv[1]);
std::ifstream file (file_to_open.c_str());
// do some awesome stuff here
return 0;
}
相关文章:
- 如何使用默认参数等选择模板专业化
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 选择要调用的构造函数
- 问:如何使用C++中的按钮从窗口打开窗口
- C++选择排序算法中的逻辑错误
- QTreeView幻灯片多选后无法使用单击选择
- SDL 窗口不会弹出
- 无法获取菜单选择以运行函数.C++
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 如何在cpp文件之间切换窗口?在Qt中
- C++文件选择窗口
- 如何修改此基于MFC的代码片段以使用自己选择的窗口类名
- 是否可以编写一个windows应用程序,当在另一个窗口应用程序中选择文本时,该应用程序会收到通知
- 更改资源管理器窗口中的选择
- 在窗口上进行组播时选择接口
- c++ MDI选择子窗口关闭
- 有选择地启用对话框/窗口的视觉样式
- 如何在另一个应用程序中选择并突出显示窗口