#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;
}
끄적대다 생각난김에...
Posted by shiftkey


