Range-based for loop debug
May 22, 2019 at 2:44pm UTC
I was expecting the code below to print out 1,2,3,5,6 and [3], however, [3] did not show up. The second for loop might be problematic but I can't figure out. Can someone help? Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "1" ;
for (int n = 2; n < 10; ++n)
{
if (n == 4) continue ;
if (n == 7)
{
cout << str << endl;
break ;
}
string lab = to_string(n);
str = str + "," + lab;
}
char compare = (char ) 3;
for (char m : str)
{
if (m == compare)
{
cout << "[" << m << "]" ;
}
}
cin.get();
}.
May 22, 2019 at 2:58pm UTC
Ascii table says that value 3
corresponds to character ETX, which is unprintable "end of text".
Character '3'
has numeric value 51.
Topic archived. No new replies allowed.