typedefvector<vector<int>>Mat;运行定义出语法错误,请大虾指教! 下面有源程序
#include<iostream>#include<fstream>#include<sstream>#include<vector>//#include<string...
#include<iostream>
#include<fstream>
#include<sstream>
#include<vector>
//#include<string>
using namespace std;
typedef vector<vector<int>> Mat;
Mat input();
void mySort(Mat &a);
void print(const Mat &a);
void main()
{
Mat a=input();
mySort(a);
print(a);
}
Mat input()
{
Mat a;
vector<int> b;
ifstream in("aaa.txt");
for(string s;getline(in,s);)
{
istringstream sin(s);
for(int ia;sin(s)>>ia;)
{
b.push_back(ia);
}
a.push_back(b);
}
//return a;
}
void mySort(Mat &a)
{
for(int pass=1;pass<a.size();++pass)
for(int i=0;i<a.size()-pass;++i)
if(a[i+1].size()<a[i].size())swap(a[i],a[i+1]);
}
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;
}
}
编译出错如下:
Compiling...
temp.cpp
D:\temp\temp.cpp(10) : error C2146: syntax error : missing ',' before identifier 'Mat'
D:\temp\temp.cpp(10) : error C2065: 'Mat' : undeclared identifier
D:\temp\temp.cpp(10) : error C2143: syntax error : missing '>' before ';'
D:\temp\temp.cpp(10) : warning C4091: 'typedef ' : ignored on left of 'class std::vector' when no variable is declared
D:\temp\temp.cpp(11) : error C2146: syntax error : missing ';' before identifier 'input'
D:\temp\temp.cpp(11) : error C2501: 'Mat' : missing storage-class or type specifiers
D:\temp\temp.cpp(11) : fatal error C1004: unexpected end of file found 展开
#include<fstream>
#include<sstream>
#include<vector>
//#include<string>
using namespace std;
typedef vector<vector<int>> Mat;
Mat input();
void mySort(Mat &a);
void print(const Mat &a);
void main()
{
Mat a=input();
mySort(a);
print(a);
}
Mat input()
{
Mat a;
vector<int> b;
ifstream in("aaa.txt");
for(string s;getline(in,s);)
{
istringstream sin(s);
for(int ia;sin(s)>>ia;)
{
b.push_back(ia);
}
a.push_back(b);
}
//return a;
}
void mySort(Mat &a)
{
for(int pass=1;pass<a.size();++pass)
for(int i=0;i<a.size()-pass;++i)
if(a[i+1].size()<a[i].size())swap(a[i],a[i+1]);
}
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;
}
}
编译出错如下:
Compiling...
temp.cpp
D:\temp\temp.cpp(10) : error C2146: syntax error : missing ',' before identifier 'Mat'
D:\temp\temp.cpp(10) : error C2065: 'Mat' : undeclared identifier
D:\temp\temp.cpp(10) : error C2143: syntax error : missing '>' before ';'
D:\temp\temp.cpp(10) : warning C4091: 'typedef ' : ignored on left of 'class std::vector' when no variable is declared
D:\temp\temp.cpp(11) : error C2146: syntax error : missing ';' before identifier 'input'
D:\temp\temp.cpp(11) : error C2501: 'Mat' : missing storage-class or type specifiers
D:\temp\temp.cpp(11) : fatal error C1004: unexpected end of file found 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询