C++ Tutorial/Development/Escape sequence

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Escape keys for double back slash

#include <iostream>
using namespace std;
int main()
{
  cout << "are quite \"useful \" \a \\ in your code \\ \a \n";
  return 0;
}
are quite "useful "  \ in your code \

Escape sequences: \b

#include <iostream> 
using namespace std; 
 
int main() 
{ 
  cout << "123\b\b45"; 
 
  return 0; 
}
145"

Escape sequences: \t

#include <iostream> 
using namespace std; 
 
int main() 
{ 
  cout << "one\ttwo\tthree\n"; 
 
  return 0; 
}
one     two     three

Use the \n code to generate a new line.

#include <iostream> 
using namespace std; 
 
int main() 
{ 
  cout << "one\n"; 
  cout << "two\n"; 
  cout << "three"; 
  cout << "four"; 
 
  return 0; 
}
one
two
threefour"