+ 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
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.
}
+ 2
nice, but the thing is that i don't reach at vector yet....
- 1
u should use java code instead of c++