Im trying to print a string to console in c++ console application.
void Divisibility::print(int number, bool divisible)
{
if(divisible == true)
{
cout << number << " is divisible by" << divisibleBy << endl;
}
else
{
cout << divisiblyBy << endl;
}
}
i have the correct includes etc, this error i believe is just that i simply dont know how to print to console in c++ yet and this i guess isnt the way to do it
EDIT: sorry forgot to mention divisiblyBy is the string
divisibleBy
are not good; you should pass it to the function as a constant reference argument. – Shaundacout
and ifcout
is attached to (going to) the console, it should be correct. If you are running this from a GUI IDE and it creates a new window which then vanishes, that is actually not directly a problem with the program but rather with the programming environment. You probably want a space after theby
in the string literal. – Shaundaiostream
on the top of your program? – EphebedivisiblyBy
isstd::string
. – Claraclarabella