Hello World in C++ [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I just started learning C++, and I found a code that doesn't work. It shows me red lines on "std_lib_facilities.h" and on cout.
I found this code in this book "Programming: Principles and Practice Using C++" by Bjarne Stroustrup.
do you recommend another book I have some experience with python and I want to move to c++
thank you
// This program outputs the message “Hello, World!” to the monitor
#include "std_lib_facilities.h"
int main() // C++ programs start by executing the function main
{
cout << "Hello, World!\n"; // output “Hello, World!”
return 0;
}

You need to include <iostream> to use cout:
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}

You need to #include <iostream> and a tip is to also type using namespace std; so you can use cin without typing std::cin

Related

Problem with the most simple program in C++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I've encountered an error with the hello world program in c++ vscode, it doesn't print out Hello World also warns me the i don't have gcc
#include <iostream.h>
using namespace stl;
integer main()
{
output << "Hello World"
return 0;
}
The source code won't compile, here is a working hello world program:
#include <iostream>
int main()
{
std::cout << "Hello World\n";
return 0;
}
In addition to this, please make sure you have a compiler.
Looks like u don't have a compiler to compile the code, consider installing gcc or any other c++ compiler first. Your source code also seems to have some syntax errors, try this hello world program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!\n";
return 0;
}

Is there a way to make the code runner not close the external terminal? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I don't know how to explain it, but I will try.
So I write C++ code and I run it with code runner. But the program closes itself. I don't want to use system("PAUSE"); because I need to remove it if I'm in a competition.
So is there another way?
Ok, I tried something that came to my mind and it works.
"code-runner.executorMap": {
"cpp": "g++ $fullFileName -o $fileNameWithoutExt.exe && start cmd /k $fileNameWithoutExt.exe"
}
I used this in the settings.json
You can use Dev C++ as an alternative IDE. But if you wish to do it in Visual Studio without a system("PAUSE"); you can use cin.get(); or cin.ignore(); as an alternative.
Code:
#include<iostream>
using namespace std;
int main()
{
cout << "Hello World";
cin.ignore();
}
or
#include<iostream>
using namespace std;
int main()
{
cout << "Hello World";
cin.get();
}

Following code is not working as expected in DEV C++ [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
The following code is not working in DEV C++:
#include <iostream>
using namespace std;
void main()
{
cout << "Hello world";
}
How can I do this?
Also, tell me if I can get almost all the functionality of Turbo C++ in Dev C++. Also, tell me if I can easily switch to DEV C++ if I know a moderate amount in Turbo C++. I just want to use C++ with Python 3.x for console applications including GUI.
From what I see in your initial question (printf works while ostream doesn't) the problem may be in buffering. Try that:
std::cout << "Hello world" << std::endl;
or, if you wish to avoid a newline:
std::cout << "Hello world";
std::cout.flush();
There is a difference between streams and printf: the streams are not outputing the data immediately but buffer that to optimize the performance. This however means that in some environments for the small outputs like yours it may stuck forever waiting for more output.
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello world";
return 0;
}
I used int main instead of void main.

I am a beginner and for some reason this does not work I am using visual studio [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
So I am a beginner and for some reason this still give me the undeclared identifier error and the system cannot find specified file errro I would be grateful if someone would answer me this
#include <iostream>
#include "stdafx.h"
using namespace std;
int main()
{
cout << "hello world" << endl;
return 0;
}
When using visual studio, this line #include "stdafx.h" needs to be at the top of your code when using pre-compiled headers.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "hello world" << endl;
return 0;
}

i receive an error saying "no operator matches these operands" for the "<<" signs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I am copying this directly from a textbook.
#include <iostream>
using namespace std;
int main()
{
string myHello = "This is Chapter 3 already?";
cout << myHello << endl; //this part is not working
return 0;
}
Why isn't this code working?
I have tried looking through the book for solutions but no solution is provided or available.
You need to #include <string> and then that'll work, do it above the using namespace command, if you got rid of the namespace command you'd need to do std::string myhello;
#include <string>