所以下面是我的代码,文件中的内容以及抛出“ std :: invalid_argument”实例后不断显示为终止的错误消息 what():stoi 中止
任何帮助将不胜感激!谢谢enter code here
---------------------------- CODE ------------------
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int size=6;
int main()
{
int friendsNumber[size]={0};
int maxFriends=0;
string friendName;
ifstream myfile;
myfile.open("myfile.txt");
while(getline(myfile,friendName,','))
{
friendsNumber[stoi(friendName)]++;
getline(myfile,friendName);
friendsNumber[stoi(friendName)]++;
}
for(int count=1;count<=5;count++)
{
if(friendsNumber[stoi(friendName)]>maxFriends)
maxFriends=friendsNumber[stoi(friendName)];
}
cout<<maxFriends;
return 0;
}
---what's inside myfile.txt---------
1,2
2,3
4,5
3,4
1,5
1,4
-----------Error-----------
terminate called after throwing an instance of 'std::invalid_argument'
what(): stoi
Aborted