Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.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

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++ 从一个字符串中获得2-5个连续的单词短语我有2个要工作,但做3个有困难 矢量单字短语; 向量双字短语; 向量三字短语; 向量::迭代器it1; 向量::迭代器it2; string str=“你好,我是bob oh hey jay oh”; 字符串拆分=str; 字符串字; stringstream(分割); while(getline(流,字,')) { 一个单词短语。推回(单词); }//用来把句子分成单词 for(it1=oneWordPhrase.begin();it1!=oneWordPhrase.end();it1++) { if(it1+1==oneWordPhrase.end()) 打破 双字短语。向后推(*it1+“”+*(it1+1)); }//获得两个单词短语 cout_C++_String_Vector_Iterator - Fatal编程技术网

C++ 从一个字符串中获得2-5个连续的单词短语我有2个要工作,但做3个有困难 矢量单字短语; 向量双字短语; 向量三字短语; 向量::迭代器it1; 向量::迭代器it2; string str=“你好,我是bob oh hey jay oh”; 字符串拆分=str; 字符串字; stringstream(分割); while(getline(流,字,')) { 一个单词短语。推回(单词); }//用来把句子分成单词 for(it1=oneWordPhrase.begin();it1!=oneWordPhrase.end();it1++) { if(it1+1==oneWordPhrase.end()) 打破 双字短语。向后推(*it1+“”+*(it1+1)); }//获得两个单词短语 cout

C++ 从一个字符串中获得2-5个连续的单词短语我有2个要工作,但做3个有困难 矢量单字短语; 向量双字短语; 向量三字短语; 向量::迭代器it1; 向量::迭代器it2; string str=“你好,我是bob oh hey jay oh”; 字符串拆分=str; 字符串字; stringstream(分割); while(getline(流,字,')) { 一个单词短语。推回(单词); }//用来把句子分成单词 for(it1=oneWordPhrase.begin();it1!=oneWordPhrase.end();it1++) { if(it1+1==oneWordPhrase.end()) 打破 双字短语。向后推(*it1+“”+*(it1+1)); }//获得两个单词短语 cout,c++,string,vector,iterator,C++,String,Vector,Iterator,当您执行*it2=oneWordPhrase.begin()+2操作时,它始终会为您提供oneWordPhrase向量中的第三个成员。您可以使用计数器而不是迭代器,因为您需要在两个向量上进行迭代: vector <string> oneWordPhrase; vector <string> twoWordPhrase; vector <string> threeWordPhrase; vector<string>::iterator it1; v

当您执行
*it2=oneWordPhrase.begin()+2
操作时,它始终会为您提供oneWordPhrase向量中的第三个成员。您可以使用计数器而不是迭代器,因为您需要在两个向量上进行迭代:

vector <string> oneWordPhrase;
vector <string> twoWordPhrase;
vector <string> threeWordPhrase;

vector<string>::iterator it1;
vector<string>::iterator it2;

string str="hello my is bob oh hey jay oh";

string split = str;
string word;
stringstream stream(split);
while( getline(stream, word, ' ') )
{
  oneWordPhrase.push_back(word);
}//used to split sentence into words

for(it1=oneWordPhrase.begin(); it1!=oneWordPhrase.end(); it1++)
{
    if(it1+1 == oneWordPhrase.end())
        break;
    twoWordPhrase.push_back(*it1 + ' ' + *(it1+1));
}//getting two word phrases

cout<<"two word---------------\n";
for(int i=0; i<twoWordPhrase.size(); i++)
    cout<<twoWordPhrase[i]<<endl;

for(it1=twoWordPhrase.begin(); it1!=twoWordPhrase.end(); it1++)
{
    it2=oneWordPhrase.begin()+2;
    threeWordPhrase.push_back(*it1 + ' ' + *it2);
    ++it2;  /* was hoping that I can get each word after "is" but it 
             didn't allow me. the problem is here */
}//getting three word phrases
cout<<"three word---------------\n";

for(int i=0; i<twoWordPhrase.size(); i++)
    cout<<threeWordPhrase[i]<<endl;
矢量单字短语;
向量双字短语;
向量三字短语;
向量::迭代器it1;
向量::迭代器it2;
string str=“你好,我是bob oh hey jay oh”;
字符串拆分=str;
字符串字;
stringstream(分割);
while(getline(流,字,'))
{
一个单词短语。推回(单词);
}//用来把句子分成单词
for(it1=oneWordPhrase.begin();it1!=oneWordPhrase.end();it1++)
{
if(it1+1==oneWordPhrase.end())
打破
双字短语。向后推(*it1+“”+*(it1+1));
}//获得两个单词短语

虽然这给了我一条额外的空白线,但这似乎是可行的。我希望使用迭代器来知道何时打破循环,就像我对OneWordPhase所做的那样。尽管如此,还是要感谢你的贡献如果你需要2到5个单词的短语,想一个对k-word短语有效的通用策略,并对不同的k-word短语运行几次。想必,无论是谁提出了这个问题,他都在寻找一个解决方案。。。
vector <string> oneWordPhrase;
vector <string> twoWordPhrase;
vector <string> threeWordPhrase;

vector<string>::iterator it1;
vector<string>::iterator it2;

string str="hello my is bob oh hey jay oh";

string split = str;
string word;
stringstream stream(split);
while( getline(stream, word, ' ') )
{
  oneWordPhrase.push_back(word);
}//used to split sentence into words

for(it1=oneWordPhrase.begin(); it1!=oneWordPhrase.end(); it1++)
{
    if(it1+1 == oneWordPhrase.end())
        break;
    twoWordPhrase.push_back(*it1 + ' ' + *(it1+1));
}//getting two word phrases

cout<<"two word---------------\n";
for(int i=0; i<twoWordPhrase.size(); i++)
    cout<<twoWordPhrase[i]<<endl;

for(int i=0; i!=twoWordPhrase.size() - 2; i++)
{
    threeWordPhrase.push_back( twoWordPhrase[i] + ' ' + oneWordPhrase[i + 2] );
      /* was hoping that I can get each word after "is" but it 
             didn't allow me. the problem is here */
}//getting three word phrases
cout<<"three word---------------\n";

for(int i=0; i<twoWordPhrase.size() - 2; i++)
    cout<<threeWordPhrase[i]<<endl;