- 1

How to print hello world with out using semicolon ; ??

its a very easy write cout statement in if condition

22nd Jun 2017, 5:45 PM
zeel kapadia
zeel kapadia - avatar
8 Respostas
+ 5
why did you use iostream.h?
22nd Jun 2017, 10:26 PM
Manual
Manual - avatar
+ 2
@zeel: You need to specify "cout" namespace, "std::cout" or add "using namespace std;" Also as @Manual pointed out, <iostream> is fine without the ".h" Finally, you can leave out the curly braces "{}" in the if-statement because we're clearly using C++, and AFAIK, main() must return int in C++ so your if should be followed by return. Full fix of your code: #include <iostream> int main() { if (std::cout << "hello world") return 0; else return 1; }
22nd Jun 2017, 11:35 PM
Jamie
Jamie - avatar
+ 2
ok thank you to clear my doubts @jamie
23rd Jun 2017, 11:49 AM
zeel kapadia
zeel kapadia - avatar
+ 1
like #include<iostream.h> void main() { if(cout<<"hello world") {} }
22nd Jun 2017, 5:47 PM
zeel kapadia
zeel kapadia - avatar
+ 1
no it is not necessary to specify "cout" usingname space std; you can run your program without it
23rd Jun 2017, 1:40 AM
zeel kapadia
zeel kapadia - avatar
+ 1
I write iostream here becoz it is the header file of c++ programs like stdio.h is a header file of c language
23rd Jun 2017, 1:42 AM
zeel kapadia
zeel kapadia - avatar
+ 1
@jamei you are almost right but read my question I ask that how to write a hello world with out using semicolon ; that means that you can't use semicolon in your whole program and I personally run my program and out put is hello world
23rd Jun 2017, 1:46 AM
zeel kapadia
zeel kapadia - avatar
+ 1
@zeel: You cannot have a return of "void" in C++ by standard. Only C allows this. "iostream" is a C++ header so we're not talking C. In C, yes it can be done: #include <stdio.h> void main () { if (printf("IDK my stuff")){} } That will work with warning, but it is C. If your C++ compiler allows void return from main() its behavior is non-standard. PS: iostream is not included with the ".h" since the mid 90s, it is no longer spec.
23rd Jun 2017, 11:29 AM
Jamie
Jamie - avatar