c++ - run time error, variable b uninitialized -


i'm writing code words line. since couldn't direct function that, code wrote. need call again , again in main program hence have made function. however, whenever call inside main loop, says variable b uninitialized. highly appreciated. tia!

vector <string> output_words(string stri) //function individual words line  {     vector <string> substring; // contains words single lines     vector <string> output1;       int b;      //create variables act "cursors". output words between them.     size_t pos1 = 0;     size_t pos2;      string str;// = "hello nme ruth";         int = str.length(); // abc[i] string in vector, not vector!      (int x = 0; x < a; x++)     {         pos2 = str.find(" ", pos1);         //substring.resize(i);         substring.resize(a); // need resize vector never points 0         substring[x] = str.substr(pos1, (pos2 - pos1));         substring.push_back(substring[x]);         //std::cout << "pos1:" << pos1 << ", pos2:" << pos2 << std::endl;         pos1 = pos2 + 1; // sets pos1 next character after pos2.                           //so, can start searching next " ".         if (x > 0)         {             if (substring[0] == substring[x])             {                 substring.erase(substring.begin() + x);                 //one_string.erase(one_string.end());                 b = x;                 goto label;             }         }     }   label: (int = 0; < b; i++)     {         output1.resize(b);         output1[i] = substring[i];      }      return output1; } 

you aren't setting variable int b; anything, literally uninitialized. have set b something(usually 0).


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -