- 3
Write with Vector in c++
Write a program that get some numbers from user If user input O ,print Odd numbers when user input E , print even numbers We should write it with vector in c++
3 RĂ©ponses
0
What is the question?
Show the code you wrote and what your problems are. It's unlikely that someone will do your homework.
0
I wrote it but I donât know how to get number from user with vector??
0
To get numbers from the user (cin) you can use
int i;
std::cin >> i;
To read several numbers into a vector you could use
int i;
std::vector<int> v;
while (std::cin >> i) {
v.push_back(i);
}
This will read numbers (and push them into the vector) until the end of the input or something is encountered, which is not a number (then the failbit is set, reset it, if you want to read from the input again)