demo_3_io_function_3.cpp

来自「对于一个初涉VC++的人来书」· C++ 代码 · 共 42 行

CPP
42
字号

//***************************************************
// 区别: 用流成员函数get或getline输入一行字符
//***************************************************

# include <iostream.h>

int main()
{
	char ch[40];
	
	cout<<"Enter a sentence: "<<endl;

	cin>>ch; //遇到空格、tab键、回车键等分隔符结束输入
	cout<<"The string read with cin is:"<<ch<<endl;

//	cin.getline(ch,40,'/');
	cin.get(ch,40,'/');
	cout<<"The second part is:"<<ch<<endl;

//	cin.getline(ch,40);
	cin.get(ch,40);
	cout<<"The third part is:"<<ch<<endl;

	return 0;
}

/*
Enter a sentence:
I like C++./I study C++ very hard./I am happy.
The string read with cin is:I
The second part is: like C++.
The third part is:I study C++ very hard./I am happy.
Press any key to continue
*******************************************************
Enter a sentence:
I like C++./I study C++ very hard./I am happy.
The string read with cin is:I
The second part is: like C++.
The third part is:/I study C++ very hard./I am happy.
Press any key to continue
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?