c++ - Stringstream trouble -


so,i'm trying conversion(integer string) , add string another.but seems stringstream not working..(it's working loop causes troubles) i'm done google & tried can't code work..anyone me :( ?

#include <iostream> #include <string> #include <sstream> using namespace std;  int main() { int n; cin>>n;  string arr[n]; string a; int i=0; int s; int c;  cin>>a; arr[i] = a; i++; cout<<"ok"<<endl; n--;  while(n--) {     cin>>a;     s = 0;      for(int j=0;j<i;j++)     {         if(arr[j] == a)         {             s = 1;             break;         }     }      i++;      if(s == 0)     {         arr[i] = a;         cout<<"ok"<<endl;     }     else     {         c++;         stringstream ss;          ss<<c;          string m = ss.str();          a+=m;          arr[i] = a;          cout<<a<<endl;          ss.str("");         ss.clear();     } }  return 0; } 

c uninitialized, should initialize it, , s before using:

int s = 0; int c = 0; 

you can't use non-const variables array initialization, consider writing:

constexpr int max_strings = 5; string arr[max_strings]; 

the loop trouble here:

i++ 

you're going on boundaries @ last element. move i++ end of while loop.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -