[C++] C++ special usage summary (1) Java-like foreach, python for

Anyone who has used Java and C# knows that there is a magical "for" statement called "foreach" that can traverse "iterable objects".
Take C# as an example:

//C#
foreach (var item in "123")
{
    
    
	System.Console.WriteLine(item);
}

Python is even more crazy, the "for" statement is used to traverse the "iterable object".

#python
for i in '123':
	print(i)

So is there a similar usage in C++?
The answer is definitely that there is a
structure similar to Java, the example is as follows

//C++
for (auto temp : "123")
{
    
    
    cout<<temp<<endl;
}

Of course, the use of such usage requires the C11 standard.
How to check what your IDE standard is, you can run the following code in the IDE to check the version

cout<<__cplusplus<<endl;

Guess you like

Origin blog.csdn.net/m0_43448982/article/details/89340353