老大们帮忙调下小程序!!
我做迷宫问题,想把坐标压入栈中 有两个数据所以做了个结构
但编译时出现问题帮忙看一下 谢谢
#include<iostream>
#include<stack>
#include<vector>
#include<sstream>
#include<fstream>
using namespace std;
struct correct{//结构含两个坐标
int x;
int y;
};
void main(){
ifstream in("abc.txt");
vector<vector<int> > matrix;
vector<int> vec;
int element;
correct cor;
stack<int> sta;
for(string s;getline(in,s);){//把abc.txt中内容读入二维向量matrix
for(istringstream sin(s);sin>>element;)vec.push_back(element);
matrix.push_back(vec);
vec.clear();
}
for(int i=0;i<matrix.size();i++){//把文档中内容压栈
cor.x=matrix[i][0];
cor.y=matrix[i][1];
sta.push(cor);//问题出现在这一行。
}
while(!sta.empty()){//输出栈中内容
cout<<sta.top()<<endl;
sta.pop();
}
}
错误提示如下:
--------------------Configuration: text - Win32 Debug--------------------
Compiling...
text.cpp
C:\Documents and Settings\江校\桌面\程序\科大复试题\text\text.cpp(26) : error C2664: 'push' : cannot convert parameter 1 from 'struct correct' to 'const int &'
Reason: cannot convert from 'struct correct' to 'const int'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
text.exe - 1 error(s), 0 warning(s)
能不能帮忙看看错在哪?还有用什么方法把坐标压如栈中比较好?
谢谢!!!