使用C+;将文本直接打印到记事本上+; 我一直尝试在C++中创建一个程序,打开一个新的记事本文件,并将文本打印到这个文件中。(就像您可以使用“cout”在运行代码时打开的命令提示符上打印文本一样)。下面是“start()”函数的一个示例,该函数可用于打开记事本和其他可执行文件 #include <iostream> #include <windows.h> using namespace std; int main(){ string text; system("start notepad.exe"); //This opens a new Notepad file. cin >> text; //I essentially would like the program to take this string of text and print it in the Notepad file. return 0; } #包括 #包括 使用名称空间std; int main(){ 字符串文本; 系统(“start notepad.exe”);//这将打开一个新的记事本文件。 cin>>文本; //我基本上希望程序获取这串文本并将其打印到记事本文件中。 返回0; }

使用C+;将文本直接打印到记事本上+; 我一直尝试在C++中创建一个程序,打开一个新的记事本文件,并将文本打印到这个文件中。(就像您可以使用“cout”在运行代码时打开的命令提示符上打印文本一样)。下面是“start()”函数的一个示例,该函数可用于打开记事本和其他可执行文件 #include <iostream> #include <windows.h> using namespace std; int main(){ string text; system("start notepad.exe"); //This opens a new Notepad file. cin >> text; //I essentially would like the program to take this string of text and print it in the Notepad file. return 0; } #包括 #包括 使用名称空间std; int main(){ 字符串文本; 系统(“start notepad.exe”);//这将打开一个新的记事本文件。 cin>>文本; //我基本上希望程序获取这串文本并将其打印到记事本文件中。 返回0; },c++,windows,C++,Windows,我正在使用最新版本的Code::Blocks IDE和Windows。任何帮助都将不胜感激 谢谢, J在程序顶部,编写#include,允许程序与文件交互。然后,使用fstream myFile初始化文件对象

我正在使用最新版本的Code::Blocks IDE和Windows。任何帮助都将不胜感激

谢谢,
J

在程序顶部,编写
#include
,允许程序与文件交互。然后,使用
fstream myFile初始化文件对象myFile.Open(“fileName.txt”,ios::out)打开/创建一个文件(如果该文件尚未存在)
若要写入文件,请使用行
myfile。我可以知道您正试图通过这种方式解决的确切问题吗?您可以使用Win32 API将合成的关键消息发送到生成的记事本进程。通过谷歌搜索
SendMessage
WM_SETTEXT
发现以下问题:。这看起来很有希望。我并没有真正解决一个特定的问题,只是在试验Windows和IDE之间的链接。制作一个程序,写出一个txt文件,然后调用记事本打开它,比使用某种机制将数据发送到记事本的运行实例更容易。