Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用c++;(将代码从Python转换为C+;+;) 我必须把代码从Python翻译成C++,但是我找不到一种方法来翻译这个部分: with open(files.square, "r") as f: # files.square is a txt file lines = f.readlines() with open(files.bs, "a") as f: # files.bs is a txt file for i, line in enumerate(lines): if line == "LINE\n": txt_line(i, line, lines) if line == "ARC\n": txt_arc(i, line, lines) #The functions txt_line and txt_arc doesn't need to be translated_Python_C++_File_Translation - Fatal编程技术网

用c++;(将代码从Python转换为C+;+;) 我必须把代码从Python翻译成C++,但是我找不到一种方法来翻译这个部分: with open(files.square, "r") as f: # files.square is a txt file lines = f.readlines() with open(files.bs, "a") as f: # files.bs is a txt file for i, line in enumerate(lines): if line == "LINE\n": txt_line(i, line, lines) if line == "ARC\n": txt_arc(i, line, lines) #The functions txt_line and txt_arc doesn't need to be translated

用c++;(将代码从Python转换为C+;+;) 我必须把代码从Python翻译成C++,但是我找不到一种方法来翻译这个部分: with open(files.square, "r") as f: # files.square is a txt file lines = f.readlines() with open(files.bs, "a") as f: # files.bs is a txt file for i, line in enumerate(lines): if line == "LINE\n": txt_line(i, line, lines) if line == "ARC\n": txt_arc(i, line, lines) #The functions txt_line and txt_arc doesn't need to be translated,python,c++,file,translation,Python,C++,File,Translation,只需要翻译文件的打开(打开时…),读取(f.readlines…)和循环(对于i,枚举中的行(行)) 基本上,我想翻译所有的代码,但我不知道如何翻译它。试试这样的方法: void txt_line(int, std::string, std::vector<std::string>){} void txt_arch(int, std::string, std::vector<std::string>){} int main() { std::ifstream f

只需要翻译文件的打开(打开时…),读取(f.readlines…)和循环(对于i,枚举中的行(行))


基本上,我想翻译所有的代码,但我不知道如何翻译它。

试试这样的方法:

void txt_line(int, std::string, std::vector<std::string>){}
void txt_arch(int, std::string, std::vector<std::string>){}

int main()
{
    std::ifstream firstFile("../square.txt");

    std::vector<std::string> contentOfFirstFile;

    std::string aLine;
    while(std::getline(firstFile, aLine))
    {
        contentOfFirstFile.push_back(aLine);
    }

    std::ifstream secondFile("../bs.txt");
    aLine.clear();

    int lineCounter = 0;
    while(std::getline(secondFile, aLine))
    {
        if(aLine == "LINE")
        {
            txt_line(lineCounter, aLine, contentOfFirstFile);
        }
        else if(aLine == "ARC")
        {
            txt_arch(lineCounter, aLine, contentOfFirstFile);
        }

        ++lineCounter;
    }

    std::cin.get();

    return 0;
}
void txt_行(int,std::string,std::vector){
void txt_arch(int,std::string,std::vector){}
int main()
{
std::ifstream第一个文件(“../square.txt”);
std::vector contentOfFirstFile;
标准:字符串对齐;
while(std::getline(firstFile,aLine))
{
contentOfFirstFile.push_back(aLine);
}
std::ifstream第二个文件(“../bs.txt”);
aLine.clear();
int lineCounter=0;
while(std::getline(secondFile,aLine))
{
如果(直线=“直线”)
{
txt_行(lineCounter、aLine、contentOfFirstFile);
}
else if(直线==“弧”)
{
txt_arch(lineCounter、aLine、contentOfFirstFile);
}
++线路计数器;
}
std::cin.get();
返回0;
}

这里有很多教程和答案,所以如何在C++中从文本文件中读取和追加。此外,还不清楚您不理解代码的哪一部分。
txt_line()
txt_arc
的定义不存在,并且这些(至少就我所知和在线快速搜索而言)不是内置的Python函数。如果你想把你的代码移植到C++,你也必须为这些函数做。我编辑了我的文章。希望它能再次帮助您:代码的哪一部分是问题?文件操作还是循环?或者两者都有?如果是循环,你只需要增加一个变量
i
,同时循环每一行并进行比较。我投票结束这个问题,因为太宽了,你尝试了什么?