Search Results for 'format'

ATOM Icon

1 POSTS

  1. 2008/04/02 StringFormat by shiftkey

StringFormat


#include <iostream>
#include <conio.h>
#include <string>
#include <stdarg.h>

using namespace std;

//////////////////////////////////////////////////////////////////////////
//cpp
string StringFormat(const int size, char* format, ...)
{
va_list argptr;
va_start(argptr, format);
char* buf = new char[size];
vsprintf(buf, format, argptr);
va_end(argptr);
string ret(buf);
delete[] buf;
return ret;
}

string StringFormat(const char* strMsg, ...)
{
char output[4096] = {NULL};
string sStrString;
va_list argptr;

sStrString.empty();

va_start(argptr, strMsg);
vsprintf(output, strMsg, argptr);
va_end(argptr);

sStrString = output;

return sStrString;
}

//////////////////////////////////////////////////////////////////////////
//MFC
// CString StringFormat(LPCTSTR strMsg, ...)
// {
// char output[4096] = {NULL};
// CString sStrString;
// va_list argptr;
//
// sStrString.Empty ();
//
// va_start(argptr, strMsg);
// vsprintf(output, strMsg, argptr);
// va_end(argptr);
//
// sStrString.Format("%s", output);
// return sStrString;
// }

int main(void)
{
int foo;
int bar;
foo = 1;
bar = 1;

cout << StringFormat("| %05d |",foo);

cout.setf(ios::right, ios::adjustfield);//오른쪽 정렬(left, right, internal)
cout.setf(ios::fixed, ios::floatfield); //부동소수 형태 설정
cout.precision(1); //정밀도 설정
cout.fill('0'); //공란을 채울 문자
//cout.setf( ios::hex, ios::basefield); // hex(16), dec(10), oct( 8 )
for (;foo<=9;foo++)
{
bar = 1;
for (;bar<=9;bar++)
{
cout.width(2); //출력 폭 설정 width는 매 cout마다 설정해야 함
cout << foo << " x ";
cout.width(2);
cout << bar << " = ";
cout.width(2);
cout << foo*bar << " "; // << endl;
if (bar == 5)
{
cout << endl;//"\t";
}
}
cout << endl;
}

system("pause");
return 0;
}


끄적대다 생각난김에...
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by shiftkey

2008/04/02 19:33 2008/04/02 19:33
, ,
Response
15 Trackbacks , No Comment
RSS :
http://shiftkey.org/rss/response/129


블로그 이미지

Shiftkey가 살아가는 이런 저런 이야기......

- shiftkey

Notices

Archives

Authors

  1. shiftkey

Calendar

«   2012/05   »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Site Stats

Total hits:
161240
Today:
21
Yesterday:
243