Open In App

How to Run a C++ Program Without Namespace?

Last Updated : 02 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite: Namespace in C++

If we want to run a program without using a namespace, we have to the std keyword along with the space resolution operator (::)  in every printing line and variable declaration,

For example, 

std::cout<<"geeksforgeeks";

Example:

C++




// C++ Program without the use of using namespace std;
#include <iostream>
#include <string>
  
int main()
{
  
    std::cout << "geeksforgeeks";
    return 0;
}


Output

geeksforgeeks

Example:

C++




// C++ Program without the use of using namespace std
#include <bits/stdc++.h>
  
int main()
{
  
    int a = 5;
    int b = 10;
    int c = a + b;
    std::cout << c << std::endl;
    return 0;
}


Output

15

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads