2017-08-01 91 views
-2

我已经创建了两个向量o3(一个向量来保存来自一个字符串的单词)和o4 (a vector to hold those vector of words). In the if statement, once ";" has been found in the vector o3 [i] , I want to stop putting words from that o3 [i]`到o4,并转到o3中的下一行。我收到错误“非标准语法使用'&'创建一个指向成员C++”的行,注释为ERROR。任何帮助,高度赞赏。谢谢!非标准语法使用'&'来创建一个指向成员C++的指针

while (getline(myfile, line, (char)32)) // first read entire line into a 
              //string 
            // problem : this also reads empty lines 
           // and gives error 
            // while returning words 
    { 
     abc2.push_back(line); // inserting individual strings into a vector 
          //cout << abc[i] << "\n"; // use this to see 
          // them as a vector of lines 
          //i++; 

    } 
for (int i = 0; i < abc.size(); i++) 
    { 
     single_line = abc[i]; 
     if (((single_line[0] >= 'A') && (single_line[0] <= 'Z')) || 
     ((single_line[0] >= 'a') && (single_line[0] <= 'z'))) 
     { 

      if (abc[i] != "") 
      { 

       o3 = output_words(abc[i], (char)32); // function to separate 
                //words in a line 
       int j1 = 0; int j2 = 0; 
       while (j2 < o3.size()) 
       { 
        if (o3[j2] != "" && "\t") // *IMP* require this line to 
               // get words 
               // irrespective of spaces 
        { 
         if (o3[j2].find != ";") // ERROR 
         { 
          o4.resize(i + 1);// NO CLUE WHY IT WORKED WITH 
              // i+1 resize???!!! 
          o4[i].push_back(o3[j2]); 
          j2++; 
         } 
         else 
         { 
          j2++; 
         } 
        } 
        else 
        { 
         j2++; 
        } 
       } 

      } 


     } 
      else 
      { 
       o3 = { "" }; // o1 will be null vector (i.e will contain 
          // nothing inside) 
       o4.push_back(o3); 
      } 


     } 
+2

请编辑您的问题以包含[mcve] – Slava

+4

您可能的意思是“如果(o3 [j2] .find(';')== std :: string :: npos)'或其某些变体。解释你想找到什么,以及一旦找到或找不到,你打算如何处理它。 –

+0

这个问题跟某个主题有关? – Slava

回答

1

表达o3[j2].find的结果是由名称find一个的o3[j2]构件。然后将该结果与完整表达式o3[j2].find != ";"中的字符串文字进行比较。

该警告消息似乎暗示,decltype(o3[j2])::find是一个成员函数。在这种情况下,成员函数的名称会衰减到成员函数指针。编译器会警告你,因为这种隐式转换是根据标准格式不正确的,但是作为编译器的语言扩展支持。标准的方法是明确地使用操作符&的地址。

比较(指向)成员函数与字符串的意义不大。您可能打算调用成员函数。要调用一个函数,可以添加由括号括起来的参数列表:o3[j2].find(/* arguments */)

假设decltype(o3[j2])std::string(您忘记声明o3),那么与字符串的比较似乎也是可疑的。 std::string::find返回找到的子字符串或字符的索引。将整数与字符串文字进行比较也没有任何意义。我建议琢磨那一行应该做什么。

相关问题