+ 1

I need explanation for std::cin>>arr[i].... I didt understand

16th Oct 2016, 3:43 AM
Pradeep C
Pradeep C - avatar
7 Respuestas
+ 3
std::cin is an object capable of reading inputs coming from standard input (usually the keyboard). When executing a code like the one you mentioned, std::cin object blocks the current thread and reads all the inputs to an internal buffer until you press "Enter" key. Once you press "Enter" std::cin object will assign the read input (partially or fully) to the given variable(s) by looking at the type(s) of the variable(s). Operator ">>" is properly overloaded to handle different known variable types. e.g: 1 int a, b, c; std::cin >> a >> b >> c; // input="10 20 30<enter>" // variables will be set as, a=10, b=20, c=30 e.g. 2 int arr[10]; std::cin >> arr[0] // first input integer value will be assigned as the first array element // this can be extended to read the i'th element in a loop
16th Oct 2016, 5:31 AM
Sumudu
Sumudu - avatar
+ 2
It's a different programming approach and difficult to explain in a few words. What I can say is, if you are going to be a programmer you must learn OOP (and other paradigms as well. like functional programming...). This has nothing to do with programming languages. Once you understand the concepts, you can use any language (and you will be able to easily learn any programming language). Don't worry about the seemingly complex name, OOP concepts are very easy to understand as long as you can understand simple real world concepts. e.g. cat is an animal, there are other animals (other-than cats), all the animals eat, some animals eat different foods, a cat has four legs etc.. There are many resources on the internet. Google is your friend. P.S. This might help you: https://www.quora.com/What-is-object-oriented-programming?srid=uuYrW
16th Oct 2016, 6:06 AM
Sumudu
Sumudu - avatar
+ 1
thankuuu bro... if u can ..could u please explain me how normal programming is different from object oriented programming ?? in short and sweet with ur own words plz ☺
16th Oct 2016, 5:34 AM
Pradeep C
Pradeep C - avatar
0
Simply array is like an empty table and you are suppose to fill it with numbers So in std::cin>>arr[i] you are simply asking the user to insert number in the table
17th Oct 2016, 3:00 AM
yousef almesbahi
yousef almesbahi - avatar
- 1
Add to. The top of the script under #include <iostream> using namespace std; and you wont need to use that methd
20th Oct 2016, 10:25 PM
OpTic Mlg Shrek
OpTic Mlg Shrek - avatar
- 1
cin allows the user to input data into a variable
20th Oct 2016, 10:26 PM
OpTic Mlg Shrek
OpTic Mlg Shrek - avatar
- 3
Ur array should be like this cin << arr[number of data in array in here] << endl;
20th Oct 2016, 10:29 PM
OpTic Mlg Shrek
OpTic Mlg Shrek - avatar