How to provide your own delimiter for cin?

一个人想着一个人 提交于 2019-12-01 17:00:34

istream.getline lets you specify a deliminator to use instead of the default '\n':

cin.getline (char* s, streamsize n, char delim );

or the safer and easier way is to use std::getline. With this method you don't have to worry about allocating a buffer large enough to fit your text.

string s;
getline(cin, s, '\t');

EDIT:

Just as a side note since it sounds like you are just learning c++ the proper way to read multiple deliminated lines is:

string s;
while(getline(cin, s, '\t')){
    // Do something with the line
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!