Some common escape sequences - C++ Language Basics

C++ examples for Language Basics:Hello World

Introduction

Escape sequence Description
\n Newline. Position the screen cursor to the beginning of the next line.
\t Horizontal tab. Move the screen cursor to the next tab stop.
\r Carriage return.
\a Alert. Sound the system bell.
\\ Backslash. Used to print a backslash character.
\' Single quote. Use to print a single quote character.
\" Double quote. Used to print a double quote character.

Printing a line of text with multiple statements.

Demo Code

#include <iostream> 

int main() {// ww w. j a  va 2  s  . co m
   std::cout << "Welcome ";
   std::cout << "to C++!\n";
   return 0;
}

Result

Printing Multiple Lines of Text with a Single Statement

Demo Code


#include <iostream>
int main() {/*from  w  ww  .  java  2  s .  co  m*/
   std::cout << "Welcome\nto\n\nC++!\n";
   return 0;
}

Result


Related Tutorials