Hi everyone ,, I think everyone get frustrated to use integer array as we need to ask for the no of input from the user unlike | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Hi everyone ,, I think everyone get frustrated to use integer array as we need to ask for the no of input from the user unlike

character arrays in c++ especially so i am posting this code for ur help where u can have integer but without asking for "how many inputs u want to enter"-- https://code.sololearn.com/czVVwHdCa8w8/?ref=app

4th Feb 2018, 1:06 PM
Arun
3 Answers
+ 2
There is a simpler way of doing this: #include <iostream> #include <vector> using namespace std; int main() { int in; vector<int> vec; while (cin >> in) vec.push_back(in); //now, you can access them like an array: cout << vec[0] << endl; cout << vec[1] << endl; //to avoid getting an error because you’re trying to access an index larger than the vector: cout << vec.size(); //returns # of elements. }
4th Feb 2018, 2:27 PM
Jacob Pembleton
Jacob Pembleton - avatar
+ 2
nice, but the thing is that i don't reach at vector yet....
4th Feb 2018, 3:27 PM
Arun
- 1
u should use java code instead of c++
7th Feb 2018, 7:37 PM
Mayur Bagul
Mayur Bagul - avatar