Stylistically, I prefer to be explicit: std::cout and std::endl.

#include <iostream>

int main(int argc, char** argv) {
  std::cout << "hello" << std::endl;
  return 0; 
}

This also fixes a tyo of yours: char, not car and repairs the #include.

This works as expected:

$ g++ -Wall -pedantic -o foo2 foo2.cpp
$ ./foo2
hello
$ 

If you wanted to, you could also use

using namespace std;

but as stated, I prefer to more explicit form.

Edit: Nothing as much fun as debating the beancounters. OP question is likely having _another error he is not sharing. His code, repaired for char actually builds:

$ cat foo3.cpp 
#include <iostream>
using std::cout;
using std::endl;

int main(int argc, char** argv) {
  cout << "hello" << endl;
  return 0; 
}
$ g++ -Wall -pedantic -o foo3 foo3.cpp
$ ./foo3
hello
$ 

Ubuntu 16.04, g++ 5.4.0

Answer from Dirk is no longer here on Stack Overflow
🌐
Linux Hint
linuxhint.com › hello-world-program-c
Hello World Program C – Linux Hint
Within its parenthesis, we have used inverted commas to add a “Hello World!” string. After this statement, you have to add the “;” semicolon to make it executable. This is the most basic syntax for the “Hello World” program. Let’s execute the code to see its output. Now, we need the C compiler in Ubuntu 20.04 to compile the code.
Top answer
1 of 3
2

Stylistically, I prefer to be explicit: std::cout and std::endl.

#include <iostream>

int main(int argc, char** argv) {
  std::cout << "hello" << std::endl;
  return 0; 
}

This also fixes a tyo of yours: char, not car and repairs the #include.

This works as expected:

$ g++ -Wall -pedantic -o foo2 foo2.cpp
$ ./foo2
hello
$ 

If you wanted to, you could also use

using namespace std;

but as stated, I prefer to more explicit form.

Edit: Nothing as much fun as debating the beancounters. OP question is likely having _another error he is not sharing. His code, repaired for char actually builds:

$ cat foo3.cpp 
#include <iostream>
using std::cout;
using std::endl;

int main(int argc, char** argv) {
  cout << "hello" << endl;
  return 0; 
}
$ g++ -Wall -pedantic -o foo3 foo3.cpp
$ ./foo3
hello
$ 

Ubuntu 16.04, g++ 5.4.0

2 of 3
2

First, make sure you have the tools you need to be able to compile a C++ code on Ubuntu. For that run the following code in the command line : This line will install all the basic stuff you need for compiling a C++ code, it will install C, C++, and make.

 sudo apt-get install build-essential

Now that you have all you need, I will suggere to explicetely using std::cout / std::endl . That way you don't import all the stuff available under the namespace std that you are not using. Using std::cout / std::endl shows clearly the origin the instance you are using. Notice : you have an error in the main function argument, namely : car, it should be char

#include<iostream>
int main(int argc, char** argv)
{
   std::cout << "hello" << std::endl;
   return 0; 
}

Now you can compile and run your code this way : in this example I'm calling the executable file "hello"

g++ -Wall -o hello aaa.cpp
./hello
Discussions

Need help with C on Ubuntu
Linking is a part of the compilation process you don’t have to think about if you are a beginner. You should focus on learning basics of the C language. Don’t even worry about a fancy IDE, just grab a text editor you like and have an open terminal to do the compiling. More on reddit.com
🌐 r/C_Programming
54
47
July 3, 2021
How to run a " C " program in Linux with Visual Studio Code.
Open a terminal. Put your source code in a file named hello.c. Here is sample source code for a “hello world” program: #include int main() { puts("hello world"); return 0; } Then type: cc -o hello hello.c This compiles hello.c into hello. Next type ./hello to run your program. More on reddit.com
🌐 r/C_Programming
19
3
October 29, 2017
🌐
UCI Engineering
laptops.eng.uci.edu › engineering-software › programming-basics › c-hello-world
C - hello world - Engineering Computer Labs & Laptops
How to run a Hello World script ... compiler, and Pico (a text editor). It uses a Linux VM. 1) With Ubuntu running on your virtual machine, open the Terminal window. 2)...
🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › tutorials › gcc-use
Develop with GCC on Ubuntu - Ubuntu for Developers
April 29, 2026 - dev@ubuntu:~/c-projects/hello-world$ gcc hello.c -o hello · This command incorporates the intermediate steps of preprocessing, compiling, and linking to generate an executable in one go. Use the -v option to display detailed information on how gcc invokes the individual tools that handle the ...
🌐
TMVTech
tmvtech.com › home › ubuntu tutorial: hello world in c with gcc
Ubuntu Tutorial: Hello world in C with GCC - TMVTech
June 14, 2024 - #include <stdio.h> int main() { printf("Hello world\n"); return 0; } Now that we have our file we can run gcc to compile it passing ‘-o’ as the executable name: ... And that’s it, a very simple program compiled with GCC.
🌐
YouTube
youtube.com › watch
Writing a Hello World program in C on an Ubuntu machine - YouTube
Shows how to get the environment for compiling C programs and demonstrates writing, compiling, and executing a Hello World program in C on an Ubuntu Desktop.
Published   November 4, 2024
Find elsewhere
🌐
Ruc
akira.ruc.dk › ~keld › teaching › CAN_e14 › Readings › How to Compile and Run a C Program on Ubuntu Linux.pdf pdf
1 How to Compile and Run a C Program on Ubuntu Linux Keld Helsgaun
#include <stdio.h> main() { printf("Hello World\n"); } Close the editor window. 4 · Step 3. Compile the program. Type the command · gcc -o hello hello.c ·
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_hello_world.htm
C - Hello World
On Ubuntu Linux, the object file is first given executable permission before running it by prefixing "./" to it. ... You can also use an IDE such as CodeBlocks to enter the code, edit, debug and run the Hello World program more conveniently.
🌐
GeeksforGeeks
geeksforgeeks.org › techtips › how-to-run-c-program-in-ubuntu
How to Run C program in Ubuntu - GeeksforGeeks
March 6, 2026 - To compile and run a C program in Ubuntu, you need the GCC compiler, which is included in the build-essential package. After installing it, you can create, compile, and execute C programs directly from the terminal.
🌐
Programmersranch
programmersranch.com › 2013 › 08 › c-hello-world-on-linux.html
C: Hello World on Linux - Programmer's Ranch
On Linux, executables don't need to have extensions such as .exe, although it's perfectly fine to include them to make it easier to recognise them. Finally, type ./hello and press ENTER to run the program. You should see "Hello world...
🌐
Saylor Academy
learn.saylor.org › mod › page › view.php
CS107: How to Compile a C/C++ Program on Ubuntu Linux | Saylor Academy | Saylor Academy
July 14, 2021 - Type: mkdir -p CCPP/HelloWorld · We are using CCPP for the main directory to hold our created C/C++ programs which stands for C and C+ + programs directory and we are using the sub directory HelloWorld to hold our main program.
🌐
Dustin John Pfister
dustinpfister.github.io › 2020 › 11 › 17 › linux-gcc
GCC Linux C compiler and C language hello world programs | Dustin John Pfister at github pages
October 9, 2021 - In this section I will be going over a very basic Hello world C language source code file called hello.c. This source code file is just a very simple typically hello world program that will just print Hello World to the standard output of the console. I then also worked out a simple bash script that will use gcc to build the hello.c file into a binary called just simply hello.
🌐
Medium
medium.com › @filip.melka › your-first-c-program-on-linux-a-quick-guide-with-vim-and-vscodium-bc941228d4b2
Your First C Program on Linux: A Quick Guide with Vim and VSCodium. | by Filip Melka | Medium
November 17, 2024 - If Vim isn’t installed, you can ... Vim · Create a new C file and open it in Vim: vim file.c · Press i to go to insert mode and write your first "Hello World" program: #include <stdio.h> int main() { printf("Hello, World!\n"); return 0; } Writing ‘Hello ...
🌐
Google Groups
groups.google.com › g › v8-users › c › 0kV28KvXt8Y
How to compile the samples/hello-world.cc example on ubuntu 64 bit ?
I have tried g++ hello-world.cc -o hello -I. but that fails with the following error : ... include/libplatform/libplatform.h:8:44: fatal error: libplatform/libplatform-export.h: No such file or directory ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... -- -- v8-users mailing list v8-u...@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group.
🌐
Scaler
scaler.com › home › topics › how to run c program in ubuntu
How to Run C Program in Ubuntu? | Scaler Topics
May 4, 2023 - First, make sure that the GCC compiler ... package using the commands provided in the above section. Use the touch command in the terminal to create a C program file. Open the hello.c file in the text editor and write a C program ...