这是我的示例代码:
#include <iostream>
#include <string>
using namespace std;
class MyClass
{
string figName;
public:
MyClass(const string& s)
{
figName = s;
}
const string& getName() const
{
return figName;
}
};
ostream& operator<<(ostream& ausgabe, const MyClass& f)
{
ausgabe << f.getName();
return ausgabe;
}
int main()
{
MyClass f1("Hello");
cout << f1;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我注释掉,#include <string>我没有得到任何编译器错误,我想因为它包含在内#include <iostream>.如果我在Microsoft VS中"右键单击 - >转到定义",它们都指向xstring文件中的同一行:
typedef basic_string<char, char_traits<char>, allocator<char> >
string;
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的程序时,我收到一个异常错误:
OperatorString.exe中的0x77846B6E(ntdll.dll):0xC00000FD:堆栈溢出(参数:0x00000001,0x01202FC4)
知道为什么我在评论时出现运行时错误#include <string> …
我正在尝试在 Windows 10 上运行一个 docker 容器,它应该执行一个 Windows 可执行文件 (myprogram.exe)。您可以在下面找到我的 dockerfile:
FROM microsoft/windowsservercore
COPY mydir/myprogram.exe /mydir/
CMD ["/mydir/myprogram.exe","someparameter"]
Run Code Online (Sandbox Code Playgroud)
因此,我使用以下命令构建映像:
docker image build --tag myimage .
并使用以下命令运行容器:
docker run myimage
不幸的是,如果我使用以下命令检查容器状态:
docker ps -a我可以看到容器已退出
退出代码 3221225781
,这似乎指向丢失的 dll。为了调试问题,我运行以下命令:
docker run -it --name debug microsoft/windowsservercore cmd停止容器并复制容器文件系统中的 Windows 可执行文件:
docker cp myprogram.exe debug:c:/myprogram.exe
现在我再次使用docker start -i debug并输入myprogram.exe myparameter. 不幸的是,程序立即退出(通常运行大约 30 秒),没有任何输出,错误代码......我对这种行为的唯一解释是,如果某些 cmd 程序缺少某些 dll,则相应的错误消息不包含在 STDERR 中,而是包含在在消息对话框中。显然 docker 不支持这个功能???所以最好的办法就是解决这个问题。使用dependency walker 来完成所有需要的dll 是可能的,但需要一些时间,我正在寻找一些更优雅的解决方案。
我在当前 python 脚本目录和子文件夹“MyFolder”中有一个名为“MyCamelCase.exe”的可执行文件。此外,在“MyFolder”中还有另一个可执行文件“DontWannaFindThis.exe”。我想找到当前目录和所有子文件夹中所有出现的“MyCamelCase.exe”。因此,我使用 Path.rglob(pattern):
from pathlib import Path
if __name__ == '__main__':
[print(f) for f in Path.cwd().rglob('MyCamelCase.exe')]
[print(f) for f in Path.cwd().rglob('.\MyCamelCase.exe')]
[print(f) for f in Path.cwd().rglob('*.exe')]
Run Code Online (Sandbox Code Playgroud)
此代码会产生以下输出:
D:\PyTesting\mycamelcase.exe
D:\PyTesting\MyFolder\mycamelcase.exe
D:\PyTesting\mycamelcase.exe
D:\PyTesting\MyFolder\mycamelcase.exe
D:\PyTesting\MyCamelCase.exe
D:\PyTesting\MyFolder\DontWannaFindThis.exe
D:\PyTesting\MyFolder\MyCamelCase.exe
Run Code Online (Sandbox Code Playgroud)
为什么 rglob 在提供完整文件名的情况下返回仅小写的字符串,而另一方面在使用带有“.*”的模式时返回包含原始符号的字符串?注意:使用 Path.glob() 时也会发生同样的情况
在我的代码中我有以下头文件:
Global.h:
#ifndef GLOBAL_H_
#define GLOBAL_H_
#include <mutex>
namespace
{
std::mutex outputMutex;
}
#endif
Run Code Online (Sandbox Code Playgroud)
Test.h:
#ifndef TEST_H_
#define TEST_H_
#include"Global.h"
#include<string>
#include<iostream>
class TestClass
{
std::string name;
public:
TestClass(std::string n):name{n}{}
void operator()()
{
for (int i=0;i<30;++i)
{
std::lock_guard<std::mutex> lock(outputMutex);
std::cout<<name<<name<<name<<name<<name<<name<<name<<std::endl;
}
}
};
#endif
Run Code Online (Sandbox Code Playgroud)
Test2.h实际上等于Test1.h,只包含一个名为"TestClass2"而不是"TestClass"的类.我的main.cpp看起来像这样:
#include<iostream>
#include <thread>
#include "Global.h"
#include "Test.h"
#include "Test2.h"
using namespace std;
int main()
{
TestClass obj1("Hello");
TestClass2 obj2("GoodBye");
thread t1(obj1);
thread t2(obj2);
t1.join();
t2.join();
}
Run Code Online (Sandbox Code Playgroud)
如果我像这样运行程序,我得到预期的输出:
HelloHelloHelloHelloHelloHelloHello
要么
GoodByeGoodByeGoodByeGoodByeGoodByeGoodByeGoodBye
到现在为止还挺好.但是当我在Test.cpp和Test2.cpp的源文件中放入Test.h和Test2.h的()--operator的定义时: …