//字符数组作为getline参数
#include <iostream>
using namespace std;
int main()
{
char ch[20];
cout << "enter a sentence:" << endl;
cin.getline(ch , 20 , '/');
cout << "The sentence is:" << ch << endl;
return 0;
}
//字符串作为getline参数
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
cout << "enter a sentence:" << endl;
getline(cin , str , '/');
cout << "The sentence is:" << str << endl;
return 0;
}
c++ getline用法实例,读取一行到字符数组+读取一行到字符串
最新推荐文章于 2024-05-23 22:10:06 发布