函数读入一行字符

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int main(int argc, char** argv) {
 6     char ch[20];
 7     cout <<"enter a sentence:"<<endl;
 8     cin>>ch;
 9     cout<<"The string read with cin is:"<<ch<<endl;
10     cin.getline(ch,20,'/');
11     cout<<"The second part is:"<<ch<<endl;
12     cin.getline(ch,20);
13     cout<<"The third part is:"<<ch<<endl;
14     return 0;
15 }

 

posted @ 2018-08-02 10:19  borter  阅读(116)  评论(0编辑  收藏  举报