This is for my CIS class and a method that is part of a blackjack game. The issue is that every "for each" statement is throwing an error, even though it seems to be written correctly. In fact, this statement was given to us by our professor to use and does not throw an error for him, but does for me.
When I build it shows the error: error C4496: nonstandard extension 'for each' used: replace with ranged-for statement.
Additionally, the "each" "in" and ")" are burning(showing error). "each" says expected a ')' the "in" says expected a ';' and the ")" says expected an expression. Any help would be greatly appreciated. Thanks in advance.
1 2 3 4 5 6 7 8 9 10 11
string showCards( vector<Card>cards)
string output = " ";
for each (Card c in cards)
output += c.toString() + " ";
That's odd, because the professor showed it the way I posted it without an error. My visual studio also will automatically format the statement if I type foreach and hit tab, but why if it isn't even c++?
To be clear, and bear with me because I am obviously learning still, the ":' is a scope resolution that is tying c to cards?
int main(array<System::String ^> ^args)
for each (int i in vec)
cout << i << '\n';
Feel free to ask more about C++\CLI in the future, but note that if you do continue to use C++\CLI and not standard C++, make sure you say this in your original post, otherwise there will be more confusion in the future.
Thank you for the help. I know that we weren't using a console application, so I did a bit more looking. Apparently the for each was acceptable with Visual Studio 15 but I am using 17 and it does not want you to write it that way anymore. The fix you gave me is actually exactly how my professor said it should be done now as well.
I'm having some other frustrating issues as well, but I think I am going to put that into a new topic so we don't clutter this one up.