填充2D字符串向量

时间:2019-11-27 11:26:54

标签: loops vector indexing 2d

我有一个称为items的2D向量,我想用words填充它。我在创建两个可以将words元素添加到2D向量的for循环时遇到麻烦。

    vector<vector<string>> items;
    vector<string> temp;
    while(getline(fin, current)) //getting data from file 
    { 
      istringstream ss(current); // current is a line that is being broken into words in the following statements

      // Traverse through all words 
      do { 
          // Read a word 
          string word; 
          ss >> word; 

          // Print the read word 
          temp.push_back(words);
          items.push_back(temp);   //this is just an attempt

          // While there is more to read 
      } while (ss); 
    }

words是一个字符串变量,其中包含诸如{“ People”“ of”“ it”“ Clement”}

之类的数据。

任何事情将不胜感激,请帮助

0 个答案:

没有答案