OutputDebugString(CString("Hello World."));
#include <iostream>
using namespace std;
class Integer {
public:
int value;
friend void operator +=(Integer &obj , int value);
friend void operator >>(int value , Integer &obj);
Integer() { value = 0; }
} obj ;
void operator +=(Integer &obj , int value) {
obj.value += value;
}
void operator >>(int value , Integer &obj) {
obj.value += value;
}
int main() {
obj += 10;
100 >> obj;
cout << obj.value;
return 0;
}
#include <iostream>
using namespace std;
void Kitty(bool b) {
try {
if (b) throw 10.1;
else throw 100;
}
catch (double e) { cout << "Exception : " << e << '\n'; }
catch (...) { cout << "Exception : Kitty()\n"; }
}
int main()
{
Kitty(true);
Kitty(false);
return 0;
}
#include <iostream>
using namespace std;
template void println(X out) {
cout << out << '\n';
}
int main() {
println("Kitty on your lap");
println(10);
println(1.052);
return 0;
}
#include <iostream>
using namespace std;
template class stack {
X box[64];
int index;
public:
bool push(X var) {
if (index > 63) return false;
box[index] = var;
index++;
return true;
}
X pop() {
if (index == 0) return NULL;
return box[--index];
}
stack() { index = 0; }
};
int main() {
stack < int > n_obj;
n_obj.push(10);
n_obj.push(100);
cout << n_obj.pop() << '\n';
cout << n_obj.pop() << '\n';
stack < char * > cp_obj;
cp_obj.push("Kitty on your lap\n");
cp_obj.push("Chobits\n");
cout << cp_obj.pop();
cout << cp_obj.pop();
return 0;
}
#include <stdio.h>
#include <stdarg.h>
void error(char *fmt, ...)
{
va_list argp;
fprintf(stderr, "error: ");
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
va_end(argp);
fprintf(stderr, "\n");
}
#include <stdlib.h> /* for malloc, NULL, size_t */
#include <stdarg.h> /* for va_ stuff */
#include <string.h> /* for strcat et al. */
char *vstrcat(char *first, ...)
{
size_t len;
char *retbuf;
va_list argp;
char *p;
if(first == NULL)
return NULL;
len = strlen(first);
va_start(argp, first);
while((p = va_arg(argp, char *)) != NULL)
len += strlen(p); va_end(argp);
retbuf = malloc(len + 1); /* おしりの\0用に+1 */
if(retbuf == NULL)
return NULL; /* エラー */
(void)strcpy(retbuf, first);
va_start(argp, first); /* 2回目のスキャンのためにリスタート */
while((p = va_arg(argp, char *)) != NULL)
(void)strcat(retbuf, p);
va_end(argp);
return retbuf;
}
// 使い方は以下のようになる。
char *str = vstrcat("Hello, ", "world!", (char *)NULL);
/*******************************************************************************
*
* 指定された 年月日 が 何曜日 かを求める。
* 何曜日かを示す 曜日番号 を返す。
* [0 = 日, 1 = 月, 2 = 火, 3 = 水, 4 = 木, 5 = 金, 6 = 土]
*
* year : 年を西暦 で与える。
* month : 月を1 ~ 12 の範囲で指定する。
* day : 日を1 ~ 31 の範囲で指定する。
*
******************************************************************************/
int getDayOfWeek(int year, int month, int day)
{
// 1月と2月を前年の13月と14月として扱う
if (month <= 2){
year -= 1;
month += 12;
}
// 曜日番号(0-6)を返す
return (day + ((8 + (13 * month)) / 5)
+ (year + (year / 4)
- (year / 100) + (year / 400))) % 7;
}
/*******************************************************************************
* 閏年(leap year)かどうかを確かめる。
* 閏年であれば真、さもなくば偽を返す
******************************************************************************/
int IsLeapYear(int year)
{
return (0 == (year % 400)) || ((0 != (year % 100)) && (0 == (year % 4)));
}
/* 配列の要素数を計算するマクロを作る。*/
#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))