해당 내용은 Pope 님의 C++ 언메니지드 프로그래밍 강좌를 공부하면서 정리하였습니다.
//오류가 발생하는 코드
// hello.h
void SayHello();
// hello2.h
void SayHello();
//main.cpp
#include "hello.h"
#include "hello2.h"
SayHello(); // 컴파일 오류 발생
// 올바른 예
namespace hello
{
void PrintHelloWorld();
}
namespace hi
{
void PrintHelloWorld();
}
hello::PrintHelloWorld();
hi::PrintHelloWorld();
#include <iostream>
using namespace std; // std를 namespace 기본으로 사용하겠다!
int main(void)
{
cout << "hello, world" << endl;
return 0;
}
int number = 123;
//양수에 플러스 사인 보여주기
cout << showpos << number; // +123
cout << noshowpos << number; // 123
//dec/hex/oct
cout << dec << number; //123
cout << hex << number; //7b
cout << oct << number; //173
//uppercase/nouppercase
cout << uppercase << hex << number; //7B
cout << nouppercase << hex << number; //7b
//showbase/noshowbase
cout << showbase << hex << number << endl; //0x7b
cout << noshowbase << hex << number << endl; //7b
//left/internal/right
cout << setw(6) << left << number; // |-123 |
cout << setw(6) << internal << number;// |- 123|
cout << setw(6) << right << number; // | -123|
float decimal1 = 100.0;
float decimal2 = 100.12;
//showpoint/noshowpoint
cout << noshowpoint << decimal1 << " " << decimal2; // 100 100.12
cout << showpoint << decimal1 << " " << decimal2; // 100.000 100.120
float number = 123.456789;
//fixed/scientific
cout << fixed << number; //123.456789
cout << scientific << number; //1.2345678E+02
//boolalpha/noboolalpha
cout << boolalpha << bReady; // true
cout << noboolalpha << bReady; // 1
#inlcude <iomanip> // 해당 헤더 있어야 setw()사용 가능
//setw()
cout << setw(5) << numnber; // | 123|
//setfill()
cout << setfill('*') << setw(5) << number; // |**123|
//setprecision()
float number = 123.456789;
cout << setprecision(7) << number; // 123.4567 : 유효숫자 정하는 조정자