- 1
How to print hello world with out using semicolon ; ??
its a very easy write cout statement in if condition
8 Respostas
+ 5
why did you use iostream.h?
+ 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;
}
+ 2
ok thank you to clear my doubts
@jamie
+ 1
like
#include<iostream.h>
void main()
{
if(cout<<"hello world")
{}
}
+ 1
no it is not necessary to specify "cout" usingname space std;
you can run your program without it
+ 1
I write iostream here becoz it is the header file of c++ programs like stdio.h is a header file of c language
+ 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
+ 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.