qt开发环境 - c++之输入,输出,名字空间定义,名字空间指令,名字空间声明

#include <QCoreApplication>
#include <iostream>

using namespace std;//包含后就不用 std::cout了,直接cout

namespace ns1 {
    int pram = 3;
    void foo(void){
        std::cout << "ns1 " << std::endl;
    }

}
namespace ns2 {
    int pram = 6;

}
namespace ns2 {
    void foo(void){
        std::cout << "ns2 " << std::endl;
    }

}
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    std::cout << "233" << std::endl;
    std::cout << "666!" << std::endl;
    std::cout << ns1::pram << std::endl;
    std::cout << ns2::pram << std::endl;
    ns1::foo();
    ns2::foo();

    using namespace ns1;//名字空间指令
    std::cout << pram << std::endl;
    foo();
//    using namespace ns2;//引发歧义
//    std::cout << pram << std::endl;
//    foo();
    using ns2::pram;//名字空间声明
    std::cout << pram <<std::endl;
    using ns2::foo;//名字空间声明
    foo();
//    using ns1::foo;//名字空间声明,这里会引起歧义
//    foo();
//    int x,y;
//    std::cin >> x >> y;
//    std::cout << x << '+' << y << " = " << x + y << std::endl;
    return a.exec();
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值