gpt4 book ai didi

c++ - 有人可以告诉我为什么这段代码不打印任何东西吗?

转载 作者:行者123 更新时间:2023-11-28 00:23:00 31 4
gpt4 key购买 nike

我必须编写一个代码来比较三个文本文件,但我终究无法找出为什么这不会打印任何内容:

#include <iostream>
#include <cstring>
#include <string>
#include <fstream>
using namespace std;

int main (int argc, char *argv[])
{
ifstream mousefile;
mousefile.open(argv[1]);
string mouse_dna;
getline(mousefile, mouse_dna);

ifstream humanfile;
humanfile.open(argv[2]);
string human_dna;
getline(humanfile, human_dna);

ifstream unknownfile;
unknownfile.open(argv[3]);
string unknown_dna;
getline(unknownfile, unknown_dna);

int len = mouse_dna.size();
int mouseDistance = 0, humanDistance = 0;

for(int i=0; i<len; i++)
if(mouse_dna[i] != unknown_dna[i])
mouseDistance++;
return mouseDistance;
for(int i=0; i<len; i++)
if(human_dna[i] != unknown_dna[i])
humanDistance++;
return humanDistance;


double similarity_scoreH = (len - humanDistance) / len;
double similarity_scoreM = (len - mouseDistance) / len;
cout << "MouseCompare = " << similarity_scoreM << endl;
cout << "HumanCompare = " << similarity_scoreH << endl;

if (similarity_scoreH == similarity_scoreM)
cout << "identity cannot be determined" << endl;
else if (similarity_scoreH > similarity_scoreM)
cout << "human" << endl;
else if (similarity_scoreM > similarity_scoreH)
cout << "mouse" << endl;


}

它编译正确,没有给出任何错误,但是当我把它写成:

./DNA mouseDNA.txt humanDNA.txt unknownDNA.txt

它仍然什么都不做。我感谢任何帮助。谢谢!

最佳答案

它不打印任何东西,因为它在打印指令之前返回(return mouseDistance;return humanDistance;)。通过在每个返回语句之前打印进度消息,使您的函数更加冗长。

关于c++ - 有人可以告诉我为什么这段代码不打印任何东西吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26542055/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com