求解...找不到错在哪了

z020807 2010-03-29 07:23:38

这程序我是完全按书上打下去的
但是都出错了
谁帮我一下

//===============================
//f0311.cpp
//若干个向量按长短排序
//===============================
#include<iostream>
#include<fstream>
#include<sstream>
#include<vector>
using namespace std;
//-------------------------------
typedef vector<vector<int>> Mat;
Mat input();
void mySort(Mat& a);
void print(const Mat& a);
//--------------------------------
int main()
{
Mat a= input();
mySort(a);
print(a);
}
//---------------------------------
Mat input()
{
ifstream in("aaa.txt");
Mat a;
for(string s; getline(in, s); )
{
vector<int> b;
istringstream sin(s);
for(int ia; sin>>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())
a[i].swqp(a[i+1])
}
//------------------------------------
void print(const Mat& a)
{
for(int i=0;i<a.size();++i)
{
for(int j=0;j<a.size();++j)
cout<<a[i][j]<<" ";
cout<<endl;
}
}




--------------------Configuration: f0311 - Win32 Debug--------------------
Compiling...
f0311.cpp
C:\Documents and Settings\Administrator\桌面\f0311.cpp(11) : error C2146: syntax error : missing ',' before identifier 'Mat'
C:\Documents and Settings\Administrator\桌面\f0311.cpp(11) : error C2065: 'Mat' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\f0311.cpp(11) : error C2143: syntax error : missing '>' before ';'
C:\Documents and Settings\Administrator\桌面\f0311.cpp(11) : warning C4091: 'typedef ' : ignored on left of 'class std::vector' when no variable is declared
C:\Documents and Settings\Administrator\桌面\f0311.cpp(12) : error C2146: syntax error : missing ';' before identifier 'input'
C:\Documents and Settings\Administrator\桌面\f0311.cpp(12) : error C2501: 'Mat' : missing storage-class or type specifiers
C:\Documents and Settings\Administrator\桌面\f0311.cpp(12) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
...全文
125 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
z020807 2010-03-29
  • 打赏
  • 举报
回复
以上`都感谢了`真心的
xboy 2010-03-29
  • 打赏
  • 举报
回复
编译器老了,vector<vector<int> >
>>尖括号之间加上空格试试,估计是编译吧 >> 当做一个运算符了
yuzl32 2010-03-29
  • 打赏
  • 举报
回复

//===============================
//f0311.cpp
//若干个向量按长短排序
//===============================
#include<iostream>
#include<fstream>
#include<sstream>
#include<vector>
using namespace std;
//-------------------------------
typedef vector<vector<int> > Mat; //空格隔开 > >
Mat input();
void mySort(Mat& a);
void print(const Mat& a);
//--------------------------------
int main()
{
Mat a= input();
mySort(a);
print(a);
}
//---------------------------------
Mat input()
{
ifstream in("aaa.txt");
Mat a;
for(string s; getline(in, s); )
{
vector<int> b;
istringstream sin(s);
for(int ia; sin>>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())
a[i].swap(a[i+1]); //缺少分号,函数应该是swap,非swqp
}
//------------------------------------
void print(const Mat& a)
{
for(int i=0;i<a.size();++i)
{
for(int j=0;j<a.size();++j)
cout<<a[i][j]<<" ";
cout<<endl;
}
}
candeabc123 2010-03-29
  • 打赏
  • 举报
回复

Mat input()
{
ifstream in("aaa.txt");
Mat a;
for(string s; getline(in, s); )
{
vector<int> b;
istringstream sin(s);
for(int ia; sin>>ia; )
b.push_back(ia); // Miss ";"a.push_back(b);
}
return a;
}

昵称很不好取 2010-03-29
  • 打赏
  • 举报
回复
typedef vector<vector<int>> Mat; --->>typedef vector<vector<int> > Mat; 两个>之间分开点,否则有可能被认为是一个>>
NesTa_xP 2010-03-29
  • 打赏
  • 举报
回复
typedef vector<vector<int> > Mat;
试一下

64,649

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧