當我運行我的程序時,我不斷收到此錯誤。該程序仍然會執行並運行並在終端中顯示正確的nymbers,但我需要它輸出另一個文件並將其放在那裏。請幫助新的C++。執行時出現C++數組錯誤
的bash-3.2 $克++ -Wall 1.cpp
1.cpp:在函數 '的std :: string IP_Calculation(的std :: string *,性病::字符串,整數)':1.cpp: 71:1:警告:控制到達非void函數的端[-Wreturn型]
string IP_Calculation(string IP[], string Company_name, int total_IPS)
{
string temp = "";
char buf[80];
char buf2[80];
if (total_IPS != 0)
{
int UniqueIP_count = total_IPS;
for (int i = 0; i < total_IPS; i++)
{
for (int j = i + 1; j < total_IPS; j++)
{
if (strcmp(IP[i].c_str(), IP[j].c_str()) == 0)
{
if (strcmp(IP[i].c_str(), "") == 0)
{
continue;
}
IP[j] = "";
UniqueIP_count--;
}
}
}
temp = print_array(IP);
cout << Company_name << " | Number of Visitor: " << total_IPS
<< "| Unique Visitors: " << UniqueIP_count << endl;
//cout<<Company_name<<" | Number of Visitor: "<<buf <<"| Unique Visitors: "<<UniqueIP_count<<endl;
cout << temp;
sprintf(buf, "%d", total_IPS);
sprintf(buf2, "%d", UniqueIP_count);
// return temp=Company_name+" | Number of Visitor: "+(total_IPS) +"| Unique Visitors: "+to_string(UniqueIP_count)+"\n"+temp+"\n";
return temp = Company_name + " | Number of Visitor: " + buf
+ "| Unique Visitors: " + buf2 + "\n" + temp + "\n";
}
}
其他代碼我不知道它爲什麼不會出現 –
cout << Company_name <<「|訪客數量:」<< total_IPS <<「|唯一訪客:」<< UniqueIP_count << endl; // cout << Company_name <<「|訪客數量:」<< buf <<「|唯一訪客:」<< UniqueIP_count << endl; cout << temp; sprintf(buf,「%d」,total_IPS); sprintf(buf2,「%d」,UniqueIP_count); // return temp = Company_name +「|訪客數量:」+(total_IPS)+「|唯一訪客:」+ to_string(UniqueIP_count)+「\ n」+ temp +「\ n」; \t return temp = Company_name +「|訪客數量:」+ buf +「|唯一訪客:」+ buf2 +「\ n」+ temp +「\ n」; \t} } –
編輯,可讀格式是強烈的首選。 – LogicStuff