最終更新 : Feb.21, 2005
■ 標準入力・出力
■ ひな型
■ 拡張子
■ 関数テンプレート
■ 参照型
■ 参照型の使用例
int i; cout << "string \n"; cin >> i; cout << i << "string \n";
#include<iostream>
using namespace std;
int main(){
}
cc cpp
template <class Tmpl>
Tmpl show( Tmpl a ){
cout << a << '\n';
return a;
}
int main(){
int i=0;
float x=0.0;
int j;
float y;
j = show( i );
u = show( x );
return( 0 );
}
int n = 0; int& refN = n; // 宣言とともに初期化が必要 refN = 1; // refN, n ともに1になる
#include<iostream>
using namespace std;
void incr( int& tmp );
int main(){
int a=5;
cout << a << '\n';
incr( a );
cout << a << '\n';
return( 0 );
}
void incr( int& tmp ){
tmp++;
}
char c;
float ha = 6562.8e-10;
cout.width(20); // 書き出し幅変更;
cout.fill('.'); // 空白文字指定
cin.get(c); //一文字読み込み
cout.put(c); //一文字書き出し
cout.precision( 12 ); // 精度の指定
cout << ha << '\n';
cout.setf(ios::right, ios::scientific); // 書式指定
cout << ha << '\n';