operator overload from setfill? weird error from code

Hey yall, I was working on my code for class and I ran into this error with this chunk of code. I can't seem to work out exactly what the problem is, but I do know it has something to do with the setfill(var9) part. Part of the assignment is printing var9 32 times across the line as well. Thanks in advance!

Here is the error, error: no match for 'operator<<' (operand types are 'std:basic_ostream<char>' and 'std::_setfill<int>'

And here is the code

1
2
3
4
5
6
7
8
9
10
11
12
13
int var9 = 100;

        do{
             cout << var9 << endl;
    }while ((var9 /= 2) > 0);

    //6D

	for(var9 = 0; var9 <= 127; var9++)
	{
		cout <<"The ASCII value is of " << (char)var9 << " is " << var9 << std::setw(32) << std::setfill(var9) << endl;
	}


I know it isn't the most particularly useful code but that was the assignment haha.
Last edited on
Yeah, template-related error messages are one of C++'s weak points.

Your problem is that std::setfill expects a character as input, not an integer.

Try
std::setfill((char)var9)
instead.
Last edited on
That worked! I took a bit of editing since the characters started displaying on the next line down instead of where they should have been, but it all works the same. I attached what I came up with, thanks so much for the simple speedy response.

1
2
3
4
for(var9 = 0; var9 <= 127; var9++)
	{
		cout << std::setw(32) << std::setfill((char)var9) << char(var9) << " = " << var9 << std::setfill(' ') << endl;
	}
Topic archived. No new replies allowed.