1

I have declared this vector vector<char> germat{ SekuencaEfjaleve.begin(), SekuencaEfjaleve.end() }; where SekuencaEfjaleve is a string that i get as an input from the user. The input always contains a space in the middle, so the user inputs something like this 423 fgfh=, and when I print out the list it stops at 3 it has only 3 elements. I read it as cin >> SekuencaEfjaleve; and i print it as

        cout << germat[i];
    }```
  • 3
    How do you read the input? How do you add it to the vector? How do you print it? Please [edit] your question to include a [mcve]. Also please read (or refresh) [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Jan 22 '21 at 07:15
  • i read it as cin >> SekuencaEfjaleve . I output it as ```for (int i = 0; i <= germat.size() - 1; i++) { cout << germat[i]; }``` –  Jan 22 '21 at 07:16
  • [`std::cin` input with spaces?](https://stackoverflow.com/questions/5838711/stdcin-input-with-spaces) – Evg Jan 22 '21 at 07:17

1 Answers1

1

Why not you use string rather then using character type vector, like this way, it is lot easier to use.

string germat;

getline(cin, germat);  // used C++ builtin function `getline()` for taking string input with spaces

// now you can access by `germat[index]`

or you can take your SekuencaEfjaleve string with getline(), like: getline(cin, SekuencaEfjaleve) and now you can access with SekuencaEfjaleve[index].

Sahadat Hossain
  • 3,583
  • 2
  • 12
  • 19
  • 1
    well it seems to work this way thank you . But it still does not asnwers the problem i had which makes this question useles –  Jan 22 '21 at 07:57