Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ getline读取C+中大写字母前分隔的文本+;_C++_String_Getline - Fatal编程技术网

C++ getline读取C+中大写字母前分隔的文本+;

C++ getline读取C+中大写字母前分隔的文本+;,c++,string,getline,C++,String,Getline,log.txt main.cpp AwBcDoFgAgHmLoCb AwCcDoAgBgHmCoZb GwDcFoFgAgNmOoBb 我的问题出现在这里,我知道如果字符串之间有分隔符。我们可以使用多个 1* AwBcDoFgAgHmLoCb 2* AwCcDoAgBgHmCoZb 3* GwDcFoFgAgNmOoBb 但是现在文本之间没有分隔符。我想在大写字母之前读入输出 Aw:Bc:Do:Fg:Ag:Hm:Lo:Cb getline(readLog,output,':');

log.txt

main.cpp

AwBcDoFgAgHmLoCb
AwCcDoAgBgHmCoZb
GwDcFoFgAgNmOoBb
我的问题出现在这里,我知道如果字符串之间有分隔符。我们可以使用多个

1*  AwBcDoFgAgHmLoCb
2*  AwCcDoAgBgHmCoZb
3*  GwDcFoFgAgNmOoBb
但是现在文本之间没有分隔符。我想在大写字母之前读入输出

Aw:Bc:Do:Fg:Ag:Hm:Lo:Cb

getline(readLog,output,':');  //output: Aw
getline(readLog,output,':');  //output: Bc
getline(readLog,output,':');  //output: Do
getline(readLog,output,':');  //output: Fg
getline(readLog,output,':');  //output: Ag
getline(readLog,output,':');  //output: Hm
getline(readLog,output,':');  //output: Lo
getline(readLog,output);      //output: Cb

很抱歉我提出了这么长的问题,因为我希望阅读和查看的人更容易理解。提前感谢您给出的答案

您可以处理读取的文本,也可以使用正则表达式拆分如下内容:

Aw
Bc
使用以下命令在组上循环:

const std::string s = "AwBcDoFgAgHmLoCb";

boost::regex words_regex("[A-Z][a-z]");

auto words_begin = 
    boost::sregex_iterator(s.begin(), s.end(), words_regex);

auto words_end = boost::sregex_iterator();
for(boost::sregex\u迭代器i=words\u begin;i!=words\u end;++i){
boost::smatch match=*i;
std::string match_str=match.str();

std::非常感谢您提供的答案。投票人,我也是来学习的,所以请不要自以为是,提供一个合理的理由。如果完全不正确,我很乐意更正它,甚至删除它。
Aw
Bc
const std::string s = "AwBcDoFgAgHmLoCb";

boost::regex words_regex("[A-Z][a-z]");

auto words_begin = 
    boost::sregex_iterator(s.begin(), s.end(), words_regex);

auto words_end = boost::sregex_iterator();
for (boost::sregex_iterator i = words_begin; i != words_end; ++i) {
    boost::smatch match = *i;                                                 
    std::string match_str = match.str(); 
    std::cout << match_str << '\n';
}