cpp_cout - 8BitsCoding/RobotMentor GitHub Wiki

์•„๋ž˜์™€ ๊ฐ™์€ ์ถœ๋ ฅ์ด ๊ฐ€๋Šฅ!

int i = 1;
double d = 2.0;
float f = 3.0;
long l = 4;
char c = 'f';
char string[] = "string";
cout << i << endl << d << endl << f << endl << l << endl << c << endl << string << endl;

๊ฒฐ๊ณผ : 1 2 3 4 f string


cout ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ์ •๋ฆฌ

// C
int num = 10;
printf("%~~) // ํ‘œ๊ธฐ๊ฐ€ ์–ด๋ ต๋‹ค.

// C++
int num = 10;
cout << showbase << hex << num << endl;
// showbase : ๋‹ค์Œ ์ง„์ˆ˜๋ฅผ ํ‘œํ˜„
// hex : 16์ง„์ˆ˜

cout << showpos << number;      // +123 -> pos๋Š” positive์˜ ์•ฝ์ž
cout << noshowpos << number;    // 123

cout << dec << number;          // 10์ง„
cout << hex << number;          // 16์ง„
cout << oct << number;          // 8์ง„

cout << uppercase << hex << number;     // ๋Œ€๋ฌธ์ž๋กœ
cout << nouppercase << hex << number;

cout << showbase << hex << number;      // showbase : ๋ช‡์ง„๋ฒ•์ธ์ง€ ํ‘œํ˜„ํ•ด ๋‹ฌ๋ผ -> 0x7b
cout << noshowbase << hex << number;

cout << setw(6) << Left << number;         // 6๊ธ€์ž ๋“ค์–ด๊ฐˆ์ˆ˜ ์žˆ๊ฒŒ ์„ธํŒ… ํ›„ ์™ผ์ชฝ์ •๋ ฌ
cout << setw(6) << internal << number;      // ๋ถ€ํ˜ธ๋Š” ์™ผ์ชฝ ์ˆซ์ž๋Š” ์˜ค๋ฅธ์ชฝ ์ •๋ ฌ
cout << setw(6) << right << numer;

cout << noshowpoint << decimal1 << " " << decimal2;     // 100 100.12 ์†Œ์ˆ˜์ ์•„๋ž˜๊ฐ€ ์—†๋‹ค๋ฉด, ๋ณด์—ฌ์ฃผ์ง€๋ง๋ผ
cout << showpoint << decial1 << " " << decimal2;        // ๋ฌด์กฐ๊ฑด ์†Œ์ˆ˜์  ํ‘œํ˜„

cout << fixed << number;        // 123.45678
cout << scientific << number;   // 1.234567E+02

cout << boolalpha << bReady;        // bReady๊ฐ€ true๋ผ๋ฉด true์ถœ๋ ฅ
cout << noboolalpha << bRead;       // 1

์—ฌ๊ธฐ์„œ๋ถ€ํ„ฐ๋Š” #include <iomaip>์„ ํ•ด์•ผ์ง€ ์‚ฌ์šฉ๊ฐ€๋Šฅ

cout << setw(5) << number;
cout << setfill('*') << setw(5) << number;      // **123 -> ๋นˆ๊ณต๊ฐ„์„ ์ฑ„์šด๋‹ค.
cout << setprecision(7) << number;              // 123.4568 -> ์†Œ์ˆ˜์ ์„ ๋ช‡์ž๋ฆฌ๊นŒ์ง€ ํ‘œํ˜„ํ•ด ์ค„์ง€ ๊ฒฐ์ •ํ•œ๋‹ค.
โš ๏ธ **GitHub.com Fallback** โš ๏ธ