Psl/c++ cheat sheet

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา

data types

  • int - for typical 32-bit integers
  • double - for floating point numbers. Sometimes, it is OK to use float, but its precision is usually not enough.
  • char - for 1-byte characters
  • long long - for large integers (64 bits)

input/output

c++: cin/cout

#include <iostream>
using namespace std;

main()
{
  int x;

  cin >> x;
  cout << "answer = " << (x+1) << endl;
}

Remarks: Don't forget the using namespace line. If you do not declare that you need to prefix cin, cout, endl with std, e.g., use std::cin.

c: printf/scanf

c-style strings