LoginSignup
4
4

More than 5 years have passed since last update.

openFrameworks-コンソール表示する

Last updated at Posted at 2016-01-19

 以下が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);
    //c_str()は、string型からchar型に戻すときに使う関数です。
    printf("[3] %sは%i歳です。\n", username.c_str(), num);
    printf("[4] %s", str);
//出力
[1]10
[2]20.000000
[3]John10歳です
[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]John10歳です
[4]Hello World

coutいいよね。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4