ostream¿¡¼­ formmating »ç¿ëÇϱâ
FrontPage|FindPage|TitleIndex|RecentChanges|UserPreferences E D R S I M H RSS

Àç¹Î±ºÀÌ ¸ÞÀÏ·Î º¸³½ ³»¿ë(³ªÁß¿¡ Á¤¸®ÇÏÀÚ¾Æ;;)

=================================================================

ÁØÈ£±ºÀÇ µµ¿òÀ¸·Î cout µîÀÇ ostream ·ù¿¡¼­ Æ÷¸ËÆÃÀ» ¸»²ûÇÏ°Ô ÇÏ´Â ¹æ¹ýÀ» ¾Ë°Ô µÇ¾ú°í, À¯¿ëÇÏ´Ù »ý°¢µÇ¾î ¼Ò°³ÇÕ´Ï´Ù.
¿ø·¡ cout·ùÀÇ Æ÷¸ËÆÃÀº ios_base¿¡¼­ ³ëÃâÇÏ´Â ÇÔ¼ö¸¦ »ç¿ëÇÏ´Â °ÍÀÌ ÀϹÝÀûÀÎ »ç¿ë¹æ¹ýÀÔ´Ï´Ù.
¿¹¸¦ µé¾î 10À» Á¤¼ö·Î Âï°í 8Áø¼ö·Î Âï°í ½Í´Ù¸é
cout<<10<<", "; cout.setf(ios_base::oct); cout<<10;
ÀÌ·± ½ÄÀ¸·Î ¾²¸é µË´Ï´Ù. ÇÏÁö¸¸ ÀÌ ¹æ½ÄÀº ÇÁ·Î±×·¥ÀÇ ³í¸®Àû È帧ÀÌ ²÷±â±â ¶§¹®¿¡ °¡µ¶¼ºÀÌ º°·Î ÁÁÁö ¾Ê½À´Ï´Ù.
À̸¦ ÇØ°áÇϱâ À§ÇØ C++¿¡¼­´Â manipulator¶ó´Â °ÍÀ» Á¦°øÇÏ°í ÀÖ½À´Ï´Ù.
°£´ÜÈ÷ ¼³¸íÇϸé ÇÔ¼ö¸¦ <<ÀÇ ÀÎÀÚ·Î ¹Þ¾Æ¼­, ±× ÇÔ¼ö¿¡ this pointer¸¦ ÀÎÀÚ·Î ³Ñ°Ü ¹ö¸®´Â °ÍÀÔ´Ï´Ù.
ÀÚ¼¼ÇÑ µ¿ÀÛÀº TC++PL ÀÇ 21.4.6À» Âü°íÇϼ¼¿ä.
µû¶ó¼­ À§ÀÇ ±¸¹®Àº ¾Æ·¡¿Í °°Àº ½¬¿î ±¸¹®À¸·Î ´ëüÇÒ ¼ö ÀÖ½À´Ï´Ù.
cout<<10<<", "<<oct<<10; //oct´Â ÇÔ¼ö Æ÷ÀÎÅÍÀÌ´Ù
Á÷°üÀûÀÌ°í °£´ÜÇÏÁö ¾Ê½À´Ï±î? ÇϳªÀÇ ¹®Á¦Á¡À̶ó¸é oct°¡ º¯¼öÀÎÁö ¹ºÁö ³×ÀÓ½ºÆäÀ̽º°¡ È¥µ¿µÈ´Ù´Â °ÍÀÔ´Ï´Ù.
½ÇÁ¦·Î Àú ±¸¹® Àü¿¡ int oct=3; ÀÌ·±½ÄÀ¸·Î ¼±¾ðµÇ¾î ÀÖÀ¸¸é ÇÔ¼öÀÇ ³×ÀÓ½ºÆäÀ̽º¸¦ µ¤¾î ¹ö·Á¼­ 10, 310 ÀÌ·±½ÄÀ¸·Î Ãâ·ÂµÇ¾î ¹ö¸³´Ï´Ù.
ÀÌ ¹æ½ÄÀ¸·Î °¡´ÉÇÑ Æ÷¸ËÆÃÀº ´Ù¾çÇÕ´Ï´Ù.
dec, hex, oct µîÀÇ Áø¼ö Ç¥ÇöÀº ¹°·Ð setw¸¦ ÅëÇÑ ÇʵåÆø Àâ±â, setprecistionÀ» ÅëÇÑ Á¤¹Ðµµ ¼³Á¤ µî..
´ÙÀ½Àº ¸î °¡Áö ¿¹Á¦ÀÔ´Ï´Ù.
cout << setw(10) << setfill('$') << -12.1 <<endl; °á°ú: $$$$$-12.1
float f = 199.9273f;
cout << "A float: " << f << ", scientific notation " << f
<< " " << scientific << f << " fixed notation " << fixed
<< f << endl;
cout << "Formatted to two decimal places " << setprecision(2)
<< f << ", formatted to %.5f " << setprecision(5) << f << endl;
°á°ú: A float: 199.927, scientific notation 199.927 1.999273e+02 fixed notation 199.927307 Formatted to two decimal places 199.93, formatted to %.5f 199.92731


¸î¸îÀº <ios>¿¡ ¸î¸îÀº <istream> <ostream> <iostream> µî¿¡ Á¤ÀǵǾî ÀÖÀ¸¸ç, À̵µÀúµµ ÇØ´çµÇÁö ¾Ê´Â ³ÑµéÀº <iomanip>¶ó´Â Çì´õ¿¡ Á¤ÀǵǾî ÀÖ½À´Ï´Ù.
ÇÔ¼ö Æ÷¸ä¸¸ ¸ÂÃ߸é Á÷Á¢ Á¤ÀÇÇÒ ¼öµµ ÀÖÀ¸¸ç Á¤ÀÇ ¹æ¹ýÀÌ ±×·¸°Ô ¾î·ÆÁöµµ ¾Ê³×¿ä. ¿ª½Ã TC++PLÀÇ 21.4.6À» Âü°í..
stream¿¡¼­ Á¦°øÇϴ ŸÀÔ ¾ÈÁ¤Àû Æ÷¸ËÆÃÀ» Àß È°¿ëÇÏ½Ã±æ ¹Ù¶ø´Ï´Ù. :)

EditText|FindPage|DeletePage|LikePages| Valid XHTML 1.0! Valid CSS! powered by MoniWiki