Unsure about using arrays | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Unsure about using arrays

Here's the code: int x = 0; int registeredStudents [10]; while (x<10) { cout << "Student #" << x+1<< ":"; cin >> registeredStudents [x] >> endl; x++; } I'll trying to insert separate names into each of the slots inside of the registeredStudents array based on x, but I keep getting a generous with pop onto my computer about the cin >> line of code. Any help appreciated.

15th Aug 2019, 12:50 AM
Thomas Wald
Thomas Wald - avatar
4 Answers
+ 2
You don't need endl after cin. You use it in cout as an alternative. https://www.sololearn.com/learn/CPlusPlus/1604/
15th Aug 2019, 2:12 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
Erm is the data a string or is it a number ?
15th Aug 2019, 1:59 AM
Leon lit
Leon lit - avatar
+ 1
My best advice, Don't often use arrays. Try and study the c++ standard template library (STL). There is what is called vector. It is quite better than arrays because it is dynamic and a lot of functions were added to it to make computing complex problems easier. Thou, it has its down side. Array is quite faster than vector with few seconds. NB: use Arrays when you know the amount of memory spaces that will be used. Use vectors when you don't know the amount of memory space that will be used up.
15th Aug 2019, 8:19 AM
Franky BrainBox
Franky BrainBox - avatar
0
Leon lit yeah I'll fix that; there array type is supposed to be string. franky I understand your advice, however I was experimenting with arrays to practice my c++ knowledge, and I haven't really learned about vectors yet. I'm just wondering what's wrong with my program, or if it's even possible to take Julie inputs and put it into an array like I'm trying to do.
15th Aug 2019, 4:21 PM
Thomas Wald
Thomas Wald - avatar