2013년 5월 28일 화요일

[C++] 문자열 자르기 샘플

문자열 자르기 간단 샘플

#include <string>
#include <iostream>

int main()
{
using namespace std;

string str( "1234567890" );
str.substr( 5 );    // "67890"
str.substr( 5, 3 ); // "678"

return 0;
}

2013년 5월 14일 화요일

[ C ][ 수학 ] 팩토리알 구하기 factorial

C언어 간단 샘플

팩토리알 구하기


#include <stdio.h>

int fact(int n)
{
if (n <= 1) return 1;
return n * fact(n - 1);
}

int main(void)
{
int n;
printf("n: ");
scanf("%d", &n);
printf("fact = %d\n", fact(n));
return 0;
}

2013년 5월 7일 화요일

[ C++ ] 파일 쓰기 샘플

C++
파일 쓰기 간단 샘플


#include <fstream>

int main()
{
std::ofstream ofs;
ofs.open( "test.txt" );

ofs << "testmessage" << 777 << std::endl;

ofs.close();
return 0;
}