+ 2

Hey freinds..I have an problem in entering elements in a userdefined array in sololearn.How can I enter elements in array in c++

19th May 2018, 5:00 AM
Yash Nirmal
Yash Nirmal - avatar
10 ответов
+ 4
int myArray[4]; for (int i = 0; i < 4; i++) { cin >> myArray[i]; } for sololearn write all the 4 inputs separating them with enter
19th May 2018, 6:03 AM
Kawaii
Kawaii - avatar
+ 1
but what if i have to give other inputs also...will it not cause any confusion😕😕
19th May 2018, 6:46 AM
Yash Nirmal
Yash Nirmal - avatar
+ 1
for (auto& element : array) cin >> element; Yash Nirmal How do you mean confusion?
19th May 2018, 8:02 AM
Timon Paßlick
+ 1
if i have to put elements in two different arrays with different sizes, can it cause confusion...??
19th May 2018, 8:19 AM
Yash Nirmal
Yash Nirmal - avatar
+ 1
Yash Nirmal Just give the user clear instructions.
19th May 2018, 8:22 AM
Timon Paßlick
+ 1
we can enter the array elemets using for loop.. syntax are given above you can check... or we can use strings also i say using strings is much good...for that you should need to enter this header file #include<stdio.h> and delcare an array eg.char a[30].it indicates the character array of 30 elemets..then text gets(a) to get array elemets..
20th May 2018, 9:37 AM
Varun Hari
Varun Hari - avatar
+ 1
Varun Hari No: #include <iostream> #include <string> std::string input; std::getline(std::cin, input); You don't need the limitation to 30.
20th May 2018, 9:39 AM
Timon Paßlick
+ 1
string.h is not part of the standard. It's called <string>.
20th May 2018, 9:42 AM
Timon Paßlick
0
kkk...we need to add string.h..:-)
20th May 2018, 9:41 AM
Varun Hari
Varun Hari - avatar
0
thankss mann..:-)
20th May 2018, 9:42 AM
Varun Hari
Varun Hari - avatar