KAIHATSUGIKEN GROUP

C++ PROGRAMMING LANGUAGE




********************************************************************************
6 キーボードからの入力
********
cin
キーボード入力を読み込む場合には、抽出演算子">>"を使います。
********
#include <iostram.h>
void main(void))
{
	int number;					//int型変数numberを準備

	cout << "Type your favorite number and pres Enter: " ;//画面に表示される
	cin >> number;		//変数numberにキーボード入力の値が保存される
	cout << "Your favorite number is " << number << endl;
							//numberの値が表示される
}
**********************************
#include <iostram.h>
void main(void)
{
	int first, second; 		//int型変数first,secondを二つ用意する

	cout << "Type two numbers separated by spaces and press Enter: ";
	cin >> first >> second;		//画面入力の値をそれぞれに代入する
	cout << "The numbers typed were " <<
	 first << " and " << second << endl;//firstとsecondをそれぞれ表示
}
***********************************
#include <iostream.h>
void main(void)
{
	char letter;			//char型文字列変数letterを準備

	cout << "Type any character and press Enter: " << endl;
	cin >> letter;		//画面入力文字列をletterに代入
	cout << "The letter typed was " << letter << endl;
							//画面出力
}
***********************************
#include <iostream.h>
void main(void)
{
	long value;		//大きな数や負の数を入力しても大丈夫な long 

	cout << "Type a large number and press Enter: ";
	cin >> value;
	cout << "The number you typed was " << value << endl;
}