Program language/C++
[C++] 네임스페이스 연습 코드 (using namespace, x::y)
COSMOSRKSI
2021. 3. 28. 12:54
#include <iostream>
#include <string>
using namespace std;
namespace worker {
char name[20] = { '0' };
int overtime = 0;
void Show(char name[], int overtime)
{
cout << "name: \t" << name << "\novertime: \t" << overtime << endl;
}
}
namespace student {
char name[20] = { '0' };
float score = 0;
void Show(char name[], int score)
{
cout << "name: \t" << name << "\nscore: \t" << score << endl;
}
}
void main()
{
using namespace student;
strcpy_s(name, 20, "abc");
score = 99.9;
Show(name, score);
cout << endl << endl;
strcpy_s(worker::name, 20, "efg");
worker::overtime = 90;
worker::Show(worker::name, worker::overtime);
}