1
Example done in Python:
editor = 'Luiz'
for contador, letra in enumerate(editor):
print(f"A letra '{letra}' está no índice {contador} ")
I was wondering if it’s possible to do this kind of counter inside the foreach
in C++, as in the above code in Python.
I noticed that in C++ there is a function called enum
, which is very similar to the enumerate
Python, but I don’t know if it does the same thing, I just compared it because I found the names of the two functions very similar. It does?
But anyway, is or is not able to put an accountant within the foreach
in C++?
Example of foreach
in C++:
#include <iostream>
using namespace std;
int main() {
string editor = "Luiz";
for (auto l : editor) cout << "Letra: " << l << endl;
return 0;
}