我正在使用CreateProcess()从我的GUI应用程序在Windows中运行外部控制台应用程序.我想以某种方式收集输出,以了解是否有错误.现在我知道我必须用hStdOutput做一些事情,但我不明白是什么.我是c ++和没有经验的程序员的新手,我实际上不知道如何处理句柄或如何点亮管道.
如何将输出转换为某种变量(或文件)?
这就是我现在所拥有的:
void email::run(string path,string cmd){
WCHAR * ppath=new(nothrow) WCHAR[path.length()*2];
memset(ppath,' ',path.length()*2);
WCHAR * pcmd= new(nothrow) WCHAR[cmd.length()*2];
memset(pcmd,' ',cmd.length()*2);
string tempstr;
ToWCHAR(path,ppath); //creates WCHAR from my std::string
ToWCHAR(cmd,pcmd);
STARTUPINFO info={sizeof(info)};
info.dwFlags = STARTF_USESHOWWINDOW; //hide process
PROCESS_INFORMATION processInfo;
if (CreateProcess(ppath,pcmd, NULL, NULL, FALSE, 0, NULL, NULL, &info, &processInfo))
{
::WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
delete[](ppath);
delete[](pcmd);
}
Run Code Online (Sandbox Code Playgroud)
这段代码可能让任何体面的程序员尖叫,但(我甚至不应该说:)它的工作原理;-)
问题:如何使用hStdOutput读取文件的输出(例如)?
如何找出C++中当前的charset是什么?
在控制台应用程序(WinXP)中,我得到一些字符(如äöüé)的负值
(int)mystring[a]
Run Code Online (Sandbox Code Playgroud)
这让我很惊讶.我期待值在127到256之间.
那么在c ++中有类似GetCharset()或SetCharset()的东西吗?
我想通过函数指针作为参数将类A的成员函数传递给类B. 请告知这条道路是否在某处领先,并帮助我填补坑洼.
#include <iostream>
using namespace std;
class A{
public:
int dosomeA(int x){
cout<< "doing some A to "<<x <<endl;
return(0);
}
};
class B{
public:
B(int (*ptr)(int)){ptr(0);};
};
int main()
{
A a;
int (*APtr)(int)=&A::dosomeA;
B b(APtr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这段精彩的代码让我遇到编译器错误:
int (A::*)(int)' to
初始化时无法转换int(*)(int)'
首先,我想要它编译.
其次,我不希望dosomeA成为STATIC.
#include <iostream>
#include <string>
using namespace std;
string mystring1, mystring2, mystring3 = "grové";
int main(){
mystring1 = "grové";
getline( cin, mystring2 ); //Here I type "grové" (without "")
cout << "mystring1= " << mystring1 << endl;
cout << "mystring2= " << mystring2 << endl;
cout << "mystring3= " << mystring3 << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上面代码的输出是:
mystring1 = grov8
mystring2 =grovémystring3
= grov8
虽然当我在这里剪切并粘贴代码时它来自:
mystring1 =grovΘmystring2
=grovémystring3
=grovΘ
为什么mystring2的内容与mystring1和mystring3不同?