0
How to do like that in C++?
listInt == [1, 2, 3, 4] for i in listInt: print(i) output: 1 2 3 4
5 odpowiedzi
+ 4
#include <iostream>
int main()
{
int list[] = { 1, 2, 3, 4 };
for (auto i : list)
std::cout << i << "\n";
}
+ 2
@Glozi30 The problem is that endl flushes the stream and then starts a new line. This is drastically slower and inefficent compared to \n by itself
+ 1
i would just add two things to the aklex answer :
* use std::endl instead of "\n" is a good use, because it makes your code easier to read.
* don't forget the return 0; at the end of the code, even if the playground on sololearn doesn't seem to need it, some compilers won't compile your code without it. There is also the int main(int argc, char*argv[]) but that is an other history and you don't need it right now.
0
@aklex "In many implementations, standard output is line-buffered, and writing '\n' causes a flush anyway, unless std::ios::sync_with_stdio(false) was executed" taken from cpp docs ^^
- 1
tks