โปรแกรม• โปรแกรม คอ รู้�ปแบื้บื้ทางต้รู้รู้กี่ะของค�าสั่��งต้�างๆ ท��น�ามารู้วมกี่�น
เพื่�อแกี่�ป!ญหาเฉพื่าะบื้างอย�าง และน�ามาใช้�สั่��งให�คอมพื่(วเต้อรู้)ท�างาน ผู้��เข�ยนโปรู้แกี่รู้มจะเข�ยนโปรู้แกี่รู้มต้ามความต้�องกี่ารู้ของน�กี่ว(เครู้าะห)รู้ะบื้บื้ หรู้ออาจกี่ล�าวได้�สั่��นๆ ว�า โปรู้แกี่รู้มหมายถึ/ง ช้0ด้ค�าสั่��งซึ่/�งถึ�กี่เข�ยนข/�นเพื่�อสั่��งให�คอมพื่(วเต้อรู้)ท�างานต้ามต้�องกี่ารู้
The Electronic Numerical Integrator And Computer (The ENIAC)
Edit-Compile-Run
กี่รู้ะบื้วนกี่ารู้พื่�ฒนาโปรู้แกี่รู้มท�� โปรู้แกี่รู้มเมอรู้)ท0กี่คนต้�องท�า
(เหมอนเป3นวงจรู้ช้�ว(ต้) กี่4คอกี่ารู้เข�ยน/ แกี่�ไข โปรู้แกี่รู้ม
กี่ารู้คอมไพื่ล)และกี่ารู้รู้�นโปรู้แกี่รู้ม
ภาษา C++• C (1972)• ANSI Standard C (1989)• C++ (1985) Bjarne Stroustrup• ANSI Standard C++ (1998)• ANSI Standard C++ [revised] (2003)
เร��มตั�นเขี�ยนโปรแกรม1 #include <iostream>23 using namespace std;45 int main()6 {7 cout << "Hello, World!" << endl;8 return 0;9 }
ขี�อผิ�ดพลัาดที่��ม�กพบบ�อย
1 #include <iostream>23 using namespace std;45 int main()6 {7 cout << "Hello, World!" << endl8 return 0;9 }
Oh No!
ขี�อผิ�ดพลัาดที่��ม�กพบบ�อย
1 #include <iostream>23 using namespace std;45 int Main()6 {7 cout << "Hello, World!" << endl;8 return 0;9 }
Oh No!
ขี�อผิ�ดพลัาดที่��ม�กพบบ�อย
1 #include <iostream>23 using namespace std;45 int main()6 {7 cout << "Hello, World!" << end1;8 return 0;9 }
Oh No!
ใช้�ตั�ว ‘ ’ แอลั ไม�ใช้� เลัขีหน"�ง
ขี�อผิ�ดพลัาดที่��ม�กพบบ�อย
1 #include <iostream>23 using namespace std;45 int main()6 {7 cout >> "Hello, World!" << end1;8 return 0;9 }
Oh No!
ใช้�เคร%�องหมาย<< ไม�ใช้� >>
การเขี�ยนโปรแกรมให�อ�านง�ายน(สั่(ต้รู้� �สั่/กี่อย�างไรู้กี่�บื้รู้�ปแบื้บื้กี่ารู้เข�ยนโปรู้แกี่รู้มแบื้บื้น�� ?
int main(){cout<<"Hello, World!"<<endl;return 0;}
ตั�วอย�างโปรแกรม 11 #include <iostream>23 using namespace std;45 int main()6 {7 cout << "Hello, ";8 cout << "World!" << endl;9 return 0;10}
สั�งเกตั'ว�าไม�ม�ค(าสั��ง endl
ตั�วอย�างโปรแกรม 21 #include <iostream>23 using namespace std;45 int main()6 {7 cout << "Hello, " << endl;8 cout << "World!" << endl;9 return 0;10}
สั�งเกตั'ว�าม�ค(าสั��ง endl
ตั�วอย�างโปรแกรม 31 #include <iostream>23 using namespace std;45 int main()6 {7 cout << "Test: ";8 cout << "1 + 2" << endl;9 return 0;10}
ลัองสั�งเกตั'เคร%�องหมายค(าพ)ด
ตั�วอย�างโปรแกรม 41 #include <iostream>23 using namespace std;45 int main()6 {7 cout << "Test: ";8 cout << 1 + 2 << endl;9 return 0;10}
สั�งเกตั'ว�า ไม�ม� เคร%�องหมายค(าพ)ด
ตั�วอย�างโปรแกรม 51 #include <iostream>23 using namespace std;45 int main()6 {7 cout << " / \\" << endl;8 cout << " / \\" << endl;9 cout << " / \\" << endl;10 cout << " -------" << endl;11 return 0;12}
สั�งเกตั'ว�าใช้�เคร%�องหมาย ‘\’ 2 อ�น