这是简单加密的一部份,请问出什么问题了?
为什么总提示:vector subscript out of range?代码如下:
#include<iostream>
#include<sstream>
#include<vector>
#include<fstream>
using namespace std;
typedef vector <vector <string>> mat;
mat input();
void jiami(mat& a);
void print(const mat& a);
int main()
{
mat a=input();
jiami(a);
print(a);
}
mat input()
{
mat a;
for(string s;getline(cin,s);)
{
vector<string> b;
istringstream sin(s);
for(string ia;sin>>ia;)
b.push_back(ia);
a.push_back(b);
}
return a;
}
void jiami(mat& a)
{
for(int i=0;i<a.size();++i)
for(int j=0;j<7;++j)
{
switch(j)
{
case 0 :a[i][j]+=4;
break;
case 1 :a[i][j]+=9;
break;
case 2 :a[i][j]+=6;
break;
case 3 :a[i][j]+=2;
break;
case 4 :a[i][j]+=8;
break;
case 5 :a[i][j]+=7;
break;
case 6 :a[i][j]+=3;
break;
default:cout<<"error"<<endl;
}
}
}
void print(const mat& a)
{
for(int i=0;i<a.size();++i)
{
for(int j=0;j<a[i].size();++j)
cout<<a[i][j]<<" ";
cout<<endl;
}
}