+ 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++
10 Antworten
+ 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
+ 1
but what if i have to give other inputs also...will it not cause any confusion😕😕
+ 1
for (auto& element : array)
cin >> element;
Yash Nirmal How do you mean confusion?
+ 1
if i have to put elements in two different arrays with different sizes, can it cause confusion...??
+ 1
Yash Nirmal Just give the user clear instructions.
+ 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..
+ 1
Varun Hari No:
#include <iostream>
#include <string>
std::string input;
std::getline(std::cin, input);
You don't need the limitation to 30.
+ 1
string.h is not part of the standard. It's called <string>.
0
kkk...we need to add string.h..:-)
0
thankss mann..:-)