Tutorials Point, posted on 24th May, 2018

C++ Standard Output Stream (cout)

cpp

#include<iostream>
int main() {
   std::cout << "Hello";
   return 0;
}

Tutorials Point, posted on 24th May, 2018

C++ Standard Error Stream (cerr)

cpp

#include<iostream>
int main() {
   std::cerr << "Hello";
   return 0;
}

Tutorials Point, posted on 24th May, 2018

C++ Manipulator setw

cpp

#include <iostream>
#include <iomanip>
int main() {
   std::cout << "no setw:" << 42 << '\n'
             << "setw(6):" << std::setw(6) << 42 << '\n'
             << "setw(6), several elements: " << 89 << std::setw(6) << 12 << 34 << '\n';
}

Tutorials Point, posted on 24th May, 2018

C++ Manipulator setprecision

cpp

#include <iostream>
#include <iomanip>
int main() {
   const long double pi = 3.141592653589793239;
   std::cout << "default precision (6): " << pi << '\n'
             << "std::setprecision(10): " << std::setprecision(10) << pi << '\n';
}

Tutorials Point, posted on 24th May, 2018

C++ Manipulator showpoint/noshowpoint

cpp

#include <iostream>
int main() {
   std::cout << "1.0 with showpoint: " << std::showpoint << 1.0 << '\n'
             << "1.0 with noshowpoint: " << std::noshowpoint << 1.0 << '\n';
}

Tutorials Point, posted on 24th May, 2018

C++ Manipulator endl

cpp

#include<iostream>
int main() {
   std::cout << "Hello" << std::endl << "World!";
}

Tutorials Point, posted on 24th May, 2018

C++ Print Hello World without semicolon

cpp

#include<iostream>

int main() {
   if (std::cout << "Hello world!") {}
}

Tutorials Point, posted on 24th May, 2018

C++ Floating-Point Constants

cpp

#include<iostream>
using namespace std;
int main() {
   const float PI = 3.141;  // 3.141 is floating point constant while PI is a constant float.
   cout << PI;
   return 0;
}

Tutorials Point, posted on 24th May, 2018

C++ Character Constants

cpp

#include <iostream>
using namespace std;
int main() {
   char newline = '\n';
   char tab = '\t';
   char backspace = '\b';
   char backslash = '\\';
   char nullChar = '\0';

   cout << "Newline character: " << newline << "ending" << endl;
   cout << "Tab character: " << tab << "ending" << endl;
   cout << "Backspace character: " << backspace << "ending" << endl;
   cout << "Backslash character: " << backslash << "ending" << endl;
   cout << "Null character: " << nullChar << "ending" << endl;
}

Tutorials Point, posted on 23rd May, 2018

C++ local variables

cpp

#include <iostream>
using namespace std;
int main () {
   int a, b;
   int c;

   a = 10;
   b = 20;
   c = a + b;

   cout << c;
   return 0;
}

1 2 3 4 5 6 7 ... 27 Next
Advertisements
Loading...