VC++6.0运行C++程序出错:'operator <<' is ambiguous

sunnydoll_sjtu 2017-04-20 09:19:28
具体程序::// mn.cpp : Defines the entry point for the console application.
//

#include <iostream.h>
#include <stdio.h>
#include <stack>
using namespace std;

typedef const __int64 ll;
typedef struct point{
int x, y;
}point;
stack<point> sp;
const int MAXN = 20;
int g[MAXN][MAXN];
point vp[MAXN+MAXN];

ll path(ll m, ll n){
if(m == 1 || n == 1) return 1;
else return path(m-1, n) + path(m, n-1);
}
ll fact(ll n){
if(n == 0) return 1;
else return n*fact(n-1);
}
ll path1(ll m, ll n){
return fact(m-1+n-1)/(fact(m-1)*fact(n-1));
}
bool get_path(int m, int n){
point p; p.x=n; p.y=m;
sp.push(p);
if(n==1 && m==1) return true;
bool suc = false;
if(m>1 && g[m-1][n])
suc = get_path(m-1, n);
if(!suc && n>1 && g[m][n-1])
suc = get_path(m, n-1);
if(!suc) sp.pop();
return suc;
}
void print_paths(int m, int n, int M, int N, int len){
if(g[m][n] == 0) return;
point p; p.x=n; p.y=m;
vp[len++] = p;
if(m == M && n == N){
for(int i=0; i<len; ++i)
cout<<"("<<vp[i].y<<", "<<vp[i].x<<")"<<" ";
cout<<endl;
}
else{
print_paths(m, n+1, M, N, len);
print_paths(m+1, n, M, N, len);
}
}
int main(){
freopen("8.2.in", "r", stdin);
for(int i=1; i<10; ++i)
cout<<path(i, i)<<endl;
cout<<endl;
for(int i=1; i<10; ++i)
cout<<path1(i, i)<<endl;
cout<<endl;
int M, N;
cin>>M>>N;
for(int i=1; i<=M; ++i)
for(int j=1; j<=N; ++j)
cin>>g[i][j];
cout<<"one of the paths:"<<endl;
get_path(M, N);
while(!sp.empty()){
point p = sp.top();
cout<<"("<<p.y<<", "<<p.x<<")"<<" ";
sp.pop();
}
cout<<endl<<"all paths:"<<endl;
print_paths(1, 1, M, N, 0);
fclose(stdin);
return 0;
}
...全文
895 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
schlafenhamster 2017-07-20
  • 打赏
  • 举报
回复
cout<<(int)path(i, i)<<endl; 对 ll 类型 无 '<<'
dfasri 2017-07-20
  • 打赏
  • 举报
回复
重载写一个 cout 对象的<<操作符就行了吧. 不过在里面也是得要强制变换成现有的<<操作符对弄的类型才行. cout是32位年代的产品, 对int64的支持可能不太好, 换成long long应该也是64位的.
schlafenhamster 2017-04-23
  • 打赏
  • 举报
回复
typedef const __int64 ll; 类型不对 改为: typedef const int ll; 试试
sunnydoll_sjtu 2017-04-23
  • 打赏
  • 举报
回复
不对啊,会出现错误: Compiling... mn.cpp f:\博士\程序\mn\mn.cpp(48) : error C2065: 'cout' : undeclared identifier f:\博士\程序\mn\mn.cpp(48) : error C2297: '<<' : illegal, right operand has type 'char [2]' f:\博士\程序\mn\mn.cpp(49) : error C2065: 'endl' : undeclared identifier f:\博士\程序\mn\mn.cpp(49) : warning C4552: '<<' : operator has no effect; expected operator with side-effect f:\博士\程序\mn\mn.cpp(59) : warning C4552: '<<' : operator has no effect; expected operator with side-effect f:\博士\程序\mn\mn.cpp(60) : warning C4552: '<<' : operator has no effect; expected operator with side-effect f:\博士\程序\mn\mn.cpp(62) : warning C4552: '<<' : operator has no effect; expected operator with side-effect f:\博士\程序\mn\mn.cpp(63) : warning C4552: '<<' : operator has no effect; expected operator with side-effect f:\博士\程序\mn\mn.cpp(65) : error C2065: 'cin' : undeclared identifier f:\博士\程序\mn\mn.cpp(65) : warning C4552: '>>' : operator has no effect; expected operator with side-effect f:\博士\程序\mn\mn.cpp(68) : warning C4552: '>>' : operator has no effect; expected operator with side-effect f:\博士\程序\mn\mn.cpp(69) : error C2297: '<<' : illegal, right operand has type 'char [18]' f:\博士\程序\mn\mn.cpp(73) : error C2297: '<<' : illegal, right operand has type 'char [2]' f:\博士\程序\mn\mn.cpp(76) : error C2297: '<<' : illegal, right operand has type 'char [11]' 执行 cl.exe 时出错. mn.obj - 1 error(s), 0 warning(s)
赵4老师 2017-04-20
  • 打赏
  • 举报
回复
缺相应对象的operator <<的实现。
oyljerry 2017-04-20
  • 打赏
  • 举报
回复
头文件改一下 #include <iostream>

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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