| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 952 人关注过本帖
标题:这个程序是哪里出错?求助!
只看楼主 加入收藏
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
结帖率:100%
收藏
 问题点数:0 回复次数:6 
这个程序是哪里出错?求助!
#include<iostream>
using namespace std;
void other();
namespace n1;
{
int x = 1;
}
namespace n2;
{
int x = 2
}
int main()
{
using namespace n1;
cout<< x <<endl;
{
int x = 4;
cout<< x <<","<<n1:: x <<endl;
}
using n2::x;
cout<< x <<endl;
other();
return 0;
}
void other()
{
using namespace n2;
cout<< x <<endl;
{
int x = 4;
cout<< x << ","<<n1::x<<","<<n2::x<<endl;
}
using n2::x<<endl;
}
搜索更多相关主题的帖子: int using namespace cout endl 
2006-11-21 10:55
smartwind
Rank: 1
等 级:新手上路
威 望:1
帖 子:277
专家分:0
注 册:2006-11-13
收藏
得分:0 
namespace n1{ }
不要在n1后面加分号
最后那一行不清楚,不过改成cout<<n2::x<<endl;可以运行

2006-11-21 11:00
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 

更正一下,还有一个错误查不出来;谁可以告诉我吗?谢谢!


#include<iostream>
using namespace std;
void other();
namespace n1
{
int x = 1;
}
namespace n2
{
int x = 2;
}
int main()
{
using namespace n1;
cout<< x <<endl;
{
int x = 4;
cout<< x <<","<<n1:: x <<endl;
}
using n2::x;
cout<< x <<endl;
other();
return 0;
void other()
{
using namespace n2;
cout<< x <<endl;
{
int x = 4;
cout<< x << ","<<n1::x<<","<<n2::x<<endl;
}
using n2::x;
cout<< x <<endl;
}


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-11-21 11:08
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 

下面分别是两个编译器的结果:
C ++ builder 6:
[C++ Error] Unit1.cpp(25): E2141 Declaration syntax error
[C++ Error] Unit1.cpp(36): E2139 Declaration missing ;
[C++ Error] Unit1.cpp(36): E2134 Compound statement missing }



VC ++ 6.0:
Compiling...
Cpp1.cpp
C:\Documents and Settings\Administrator\My Documents\Microsoft Visual C++\Cpp1.cpp(25) : error C2601: 'other' : local function definitions are illegal
C:\Documents and Settings\Administrator\My Documents\Microsoft Visual C++\Cpp1.cpp(35) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Cpp1.obj - 2 error(s), 0 warning(s)


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-11-21 11:16
dubaoshi
Rank: 1
等 级:新手上路
帖 子:118
专家分:0
注 册:2006-9-22
收藏
得分:0 

我来说一说,嘿嘿:
#include<iostream>
using namespace std;
void other();
namespace n1;//这里不加分号
{
int x = 1;
}
namespace n2;//这里不加分号
{
int x = 2//这里需要加分号
}
int main()
{
using namespace n1;
cout<< x <<endl;
{
int x = 4;
cout<< x <<","<<n1:: x <<endl;
}
using n2::x;
cout<< x <<endl;
other();
return 0;
}
void other()
{
using namespace n2;
cout<< x <<endl;
{
int x = 4;
cout<< x << ","<<n1::x<<","<<n2::x<<endl;
}
using n2::x<<endl;//这里去掉<<endl
}
我这样运行就OK了,你试一下吧。


人行善,福虽未至,祸已远离;人行恶,祸虽未至,福已远离.
2006-11-21 11:53
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 

嘿嘿 ,谢谢。可以啦


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-11-21 12:27
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
还可以帮忙看看这个程序吗?
Microsoft Visual C++\Cpp1.cpp(33) : error C2872: 'y' : ambiguous symbol


#include<iostream>
using namespace std;
void other();
void another();
int x = 10;
int y;
int main()
{
cout<< x <<endl;
{
int x =4;
cout<< x <<endl;
cout<< y <<endl;
}
other();
another();
return 0;
}
void other()
{
int y =1;
cout<< "other"<< x <<","<< y <<endl;
}
#include<iostream>
using namespace std;
extern int x;
namespace
{
int y = -4;
}
void another()
{
cout<<"another():"<< x <<","<< y <<endl;
}

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2006-11-21 12:55
快速回复:这个程序是哪里出错?求助!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042050 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved