+ 1
hello can you help me to right a cod
5 Answers
+ 2
yes. Write
print("Hello, world!")
+ 2
C++ version of that:
#include <iostream>
using namespace std;
int main() {
cout << âHello, world!â;
}
+ 1
thanks
0
Explanation of both C++ versions:
Mine:
#include <iostream>
//This tells the compiler to include the input and output header. It allows you to output to the console and get input from the user.
using namespace std;
//A namespace in C++ is a group of functions, classes, anything like that organized in a system similar to folders. âstdâ is the standard namespace. It is considered bad practice to use this because it could cause an error if you are using multiple namespaces.
int main() { /*code*/}
//This defines the main function. That is what runs when the program starts.
cout << âHello, world!â;
//This is what actually outputs the text. cout is a keyword in the standard namespace for console output, << is the output operator. It is also used for output to files.
The semicolon shows that the statement is over.
@Vladâs version:
//Most stayed the same, but some differences. Instead of âusing namespace std;â, it has âstd::â in front of everything from that namespace. This avoids errors that can occur in my version, but is not necessary if you are only using one namespace because the error can only come from conflicting namespaces.
std::cout << âHello, world!â << std::endl;
//There are a few new things in this. First, the extra â<<â. You can have as many of these as you want, they will just all be outputted. Second, std::endl is like pressing enter on the keyboard, it ends the line. endl also does this: cout.flush(). For just ending the line, you could do this:
std::cout << âHello, world!\nâ;
\n just ends the line.
- 1
Better C++ version of that:
#include <iostream>
int main()
{
std::cout << âHello, world!â << std::endl;
return 0:
}