【oF】コンソール表示について
以下が2つがopenFrameworksでのコンソールの表示方法。oFというかC++ですね。
- printf
- cout
printfは変数の型など配慮する点が多く、ゆるく使えるcout(読み:シーアウト)を使った方がいいかもしれない。
1.printf出力
変数の型を考慮する必要がある。
改行は\n
//入力 int num = 10; float fnum = 20.0; string username = "John"; char str[255] = "Hello World"; printf("[1]: %i \n", num); printf("[2]: %f \n", fnum); printf("[3]: %sは%i歳です。\n", username.c_str(), num);//c_str()は、string型からchar型に戻すときに使う関数です。 printf("[4]: %s", str);
//出力 [1]: 10 [2]: 20.000000 [3]: Johnは10歳です。 [4]: Hello World
2.cout出力
型を考慮しないで出力できるのでprintfより楽
coutでは、endlで改行を行う。
//入力 int num = 10; float f_num = 20.333333333; string username = "John"; char str[255] = "Hello World"; cout<<"[1]:"<<num<<endl; cout<<"[2]:"<<f_num<<endl; cout<<"[3]:"<<username<<"は"<<num<<"歳です"<<endl; cout<<"[4]:"<<str<<endl;
//出力 [1]:10 [2]:20.3333 [3]:Johnは10歳です [4]:Hello World
coutいいよね。