Sunday, July 12, 2009

C++ help!!?

I want to print using cout with an argument.. if the argument returns a true print this, if it returns this print this.





Don't use IFs.. I think it's something like this...





cout %26lt;%26lt; (argument) ? : "hello" : "bye";





that doesn't compile, but the syntax is something like that.





C++ expert please help.

C++ help!!?
drop the : between ? and "hello", i.e.





(argument) ? "hello" : "bye"











This syntax is also supported in many other languages beside C/C++.





However, in the business world, it is often considered a security risk for reasons I have yet to comprehend.
Reply:cout %26lt;%26lt; (argument) ? : "hello" : "bye";//its wrong


cout %26lt;%26lt; (argument) ? "hello" : "bye";//use this
Reply:previous answerer is correct. Just follow him. The line should compile.


cout%26lt;%26lt; (arguement)? "print this" : "otherwise print this ";
Reply:It's not an argument. An argument is a parameter to a function, and you're not calling a function.





It's:





cout %26lt;%26lt; ((expression) ? "hello" : "byte");


No comments:

Post a Comment