使用记事本C++打开 txt 文件时无需等待
Not waiting when open a txt file with notepad C++
当我在C++中使用记事本打开.txt文件时,我的程序在关闭记事本之前不会继续。
如何让我的代码继续而不是像这样等待?
法典:
string a;
string topicName;
a = "C:\Hello\Hi\Hi.txt";
topicName = "notepad "" + a + """;
system(topicName.c_str());
使用 popen 而不是system
。
#include <iostream>
int main() {
popen("notepad.exe", "r");
std::cout << "I'm still running!" << std::endl;
}
我在 Windows 10 64 位上用g++
编译了它,它可以工作。
如果你愿意使用system
函数,你可以用start
shell 函数打开记事本:
system("start notepad c:\my\path\hello.txt");
start
shell 函数在后台运行。它就像在屏幕上"点击"了什么东西一样。因此,如果您想在默认编辑器而不是记事本中打开hello.txt
。您还可以执行以下操作:
system("start c:\my\path\hello.txt");
当然,这是特定于Windows的,并且许多人不建议在生产代码中使用system
。
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- 使用记事本C++打开 txt 文件时无需等待
- 有没有办法等待文件在纯 c++ 中写入?
- 正在等待在非阻塞文件描述符上长时间运行ioctl
- 等待创建文件
- 等待文件存在并且不被其他人占用
- 所有线程都在核心转储文件中等待,但有人触发了SIG_ABRT
- 打开通过蓝牙发送的已接收文件-如何等待完全接收
- 关闭后等待文件删除
- Win32 读取文件输出,无需等待缓冲区
- 如何用WaitForSingleObject发出等待文件HANDLE的信号
- 停止并等待文件传输协议,何时停止侦听
- 如何在写入文件时等待
- 当exe文件无效时,CreateProcess将等待
- 在Linux上,从C++调用一个可执行文件,然后等待它完成
- 等待,直到pdf文件被病毒扫描检查
- 每次一行显示文本文件,等待用户输入
- 打开一些文件,等待大约30分钟,在C++中重新启动它们