问题
I want to display hello world message in c++ without using semicolon. how can I do that? Is it possible? I have tried it inside if else block like
if(true) {
cout<<"hello world"
}
but it does not work like that.
回答1:
if (cout << "hello world") {}
回答2:
You can put it as the condition:
if (std::cout << "hello world") {}
回答3:
You can use if
, for
or while
, maybe more.
if(std::cout << "Hello World") { }
while(std::cout << "Hello World" && false) { } // && false to loop only once
for(std::cout << "Hello World"; false;) { } // has semicolons, but not at the end of line ;)
Or put it on the next line:
std::cout << "Hello World 4"\
;
来源:https://stackoverflow.com/questions/59990046/how-can-i-use-couthello-world-without-using-at-the-end-of-the-line