0

How to C++

Recently started to learn C++, and I have stumbled upon many problems. How to print the whole array? How to extract inputs like ‘1 2 3’ (when I print it it shows 1) And some more things that the lessons doesn’t explain. Links are welcome.

11th Feb 2020, 2:15 PM
FORT
FORT - avatar
2 Answers
+ 5
I suppose your primary language is Python? Many of the concepts you have learned will still apply to C++, but there may not be as many handy methods or features which will make your life as easy, e.g. printing an entire list, splitting a string to tokens, etc. It takes time to get used to, just like when I tried Python after learning C++. Just as a meta-advice, feel free to create different threads in the Q&A for different topics you have doubts on, but remember to use the search bar to make sure the query is not a duplicate.
11th Feb 2020, 2:34 PM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Feels like you've potentially compressed a ton of threads into one. Just to answer those doubts you've made clear: 1) Loops. Since we access array elements via index, you can iterate through the whole array and print its elements one by one. Should the size of the array be N, and your array arr, for (int i = 0; i < N; i++) std::cout << arr[i]; or even better, range-based for loops. for (auto i : arr) std::cout << i; https://en.cppreference.com/w/cpp/language/range-for 2) "Extractions on cin can also be chained to request more than one datum in a single statement" int a, b, c; cin >> a >> b >> c; http://www.cplusplus.com/doc/tutorial/basic_io/
11th Feb 2020, 2:28 PM
Hatsy Rei
Hatsy Rei - avatar