#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