#include<iostream>
using namespace std; //关于这里,且听下回分解
int main()
{
cout<<"Hello imooc"; //在此填写我们的开篇Hello imooc
return 0;
}
using namespace std; //关于这里,且听下回分解
int main()
{
cout<<"Hello imooc"; //在此填写我们的开篇Hello imooc
return 0;
}
2017-08-11
试了半天,去掉endl就对了。奉献给强迫症的同学们,如下所示:
cout<<"Hello imooc"; //在此填写我们的开篇Hello imooc
cout<<"Hello imooc"; //在此填写我们的开篇Hello imooc
2017-08-10
namespace myNum
{
int x = 105;
}
int main()
{
bool isFlag = false;
if(myNum::x % 2 == 0)
{
isFlag = false;
}
else
{
isFlag = true;
}
if(isFlag)
{
cout << myNum::x << "是奇数"<< endl;
}
else
{
cout << myNum::x << "是偶数"<< endl;
}
return 0;
}
{
int x = 105;
}
int main()
{
bool isFlag = false;
if(myNum::x % 2 == 0)
{
isFlag = false;
}
else
{
isFlag = true;
}
if(isFlag)
{
cout << myNum::x << "是奇数"<< endl;
}
else
{
cout << myNum::x << "是偶数"<< endl;
}
return 0;
}
int main(void) {
cout << A::x << endl;
B::f1();
system("pause");
return 0;
}
}
cout << A::x << endl;
B::f1();
system("pause");
return 0;
}
}
2017-08-08
#include <iostream>
#include <stdlib.h>
using namespace std;
namespace A {
int x = 0;
void f1() {
cout << "A" << endl;
}
void f2() {
cout << "B" << endl;
}
namespace B {
int x = 2;
void f1() {
cout << "A" << endl;
}
void f3() {
cout << "C" << endl;
}
}
请问这个错哪?
#include <stdlib.h>
using namespace std;
namespace A {
int x = 0;
void f1() {
cout << "A" << endl;
}
void f2() {
cout << "B" << endl;
}
namespace B {
int x = 2;
void f1() {
cout << "A" << endl;
}
void f3() {
cout << "C" << endl;
}
}
请问这个错哪?
2017-08-08
刚发现C++命名空间得定义了才能使用。之前我把using namespace B;放在B定义前,结果编译的时候报错
g++ first.cpp -o first
first.cpp:4:17: error: ‘B’ is not a namespace-name using namespace B;
first.cpp:4:18: error: expected namespace-name before ‘;’ token using namespace B;
(字数限制,剩下的贴不上来了)
g++ first.cpp -o first
first.cpp:4:17: error: ‘B’ is not a namespace-name using namespace B;
first.cpp:4:18: error: expected namespace-name before ‘;’ token using namespace B;
(字数限制,剩下的贴不上来了)
2017-08-05