0

Arrays

How to add a value from user into a array?

5th Jun 2024, 11:59 AM
user99998CCCCC
user99998CCCCC - avatar
4 Respostas
+ 5
#include<bits/stdc++.h> using namespace std; int main(){ vector<int>array; int element; while(cin>>element){ array.push_back(element); } return 0; } This will add all the integer values from the user separate by space into an array.
5th Jun 2024, 2:33 PM
Gulshan Mahawar
Gulshan Mahawar - avatar
0
If you have a fixed length array then you could do: int nums[] = { -1, -1, -1 }; nums[0] = usersInput; Where -1 is no input yet provided.
5th Jun 2024, 12:15 PM
Kai Harrison
0
Kai Harrison Why not just do it like this if it's a fixed length...... int nums[3];
5th Jun 2024, 7:58 PM
Jan
Jan - avatar
0
Jan Nothing’s stopping you 😃
6th Jun 2024, 9:27 AM
Kai Harrison