首页 > 解决方案 > C++ 应用程序不读取 json 文件 - Docker 容器

问题描述

我编写了执行计算的 ac++ 程序。值应该从 JSON 文件中读取,然后存储在变量中。我现在已经在 Docker 容器(alpine)中启动了这个应用程序。在应用程序中,除了从 JSON 文件中读取数据外,一切正常。在容器之外,程序运行没有问题。

这会是什么?Docker 是否需要为 .JSON 文件指定不同的目录?或者为什么会这样?

C++:

// filestream variable file 
std::fstream file; 
std::string word, filename;
std::string stringA= ""; 

// filename of the file 
filename = "TestX.json"; 

// opening file 
file.open(filename.c_str()); 

// extracting words form the file 
while (file >> word) 
{ 
    if((word.find("ABC",0))!=-1){
        file >> word;
        stringA= word;
    }

    if((word.find("CDE",0))!=-1){
        file >> word;
        stringB = word;
    }

    if((word.find("EFG",0))!=-1){
        file >> word;
        stringC = word;
    }

    if((word.find("GHI",0))!=-1){
        file >> word;
        stringD = word;
    }
}

码头工人命令:

docker run -it -p 8080:1234 test

标签: c++docker

解决方案


推荐阅读