ผลต่างระหว่างรุ่นของ "Psl/c++ cheat sheet"
ไปยังการนำทาง
ไปยังการค้นหา
Jittat (คุย | มีส่วนร่วม) (หน้าที่ถูกสร้างด้วย '== data types == == input/output == == c-style strings ==') |
Jittat (คุย | มีส่วนร่วม) |
||
(ไม่แสดง 4 รุ่นระหว่างกลางโดยผู้ใช้คนเดียวกัน) | |||
แถว 1: | แถว 1: | ||
== data types == | == data types == | ||
+ | |||
+ | * <tt>int</tt> - for typical 32-bit integers | ||
+ | * <tt>double</tt> - for floating point numbers. Sometimes, it is OK to use <tt>float</tt>, but its precision is usually not enough. | ||
+ | * <tt>char</tt> - for 1-byte characters | ||
+ | * <tt>long long</tt> - for large integers (64 bits) | ||
== input/output == | == input/output == | ||
+ | |||
+ | === c++: cin/cout === | ||
+ | <syntaxhighlight lang="cpp"> | ||
+ | #include <iostream> | ||
+ | using namespace std; | ||
+ | |||
+ | main() | ||
+ | { | ||
+ | int x; | ||
+ | |||
+ | cin >> x; | ||
+ | cout << "answer = " << (x+1) << endl; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | '''Remarks''': Don't forget the <tt>using namespace</tt> line. If you do not declare that you need to prefix cin, cout, endl with <tt>std</tt>, e.g., use <tt>std::cin</tt>. | ||
+ | |||
+ | === c: printf/scanf === | ||
== c-style strings == | == c-style strings == |
รุ่นแก้ไขปัจจุบันเมื่อ 23:24, 7 มกราคม 2561
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.