Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

ความแตกต่างระหว่าง STL และ C++ Standard Library


STL (Standard Template Library) เป็นไลบรารีซอฟต์แวร์สำหรับ C++ ที่มีอิทธิพลต่อหลายส่วนของ C++ Standard Library ประกอบด้วย 4 ส่วนหลัก: algorithms, containers, functions, iterators

สำคัญ: คำว่า "STL" ไม่ได้ปรากฏในมาตรฐาน ISO 14882 C++ เลย การเรียก C++ Standard Library ว่า STL จึงไม่ถูกต้อง - STL เป็นเพียง subset ของ Standard Library

STL ประกอบด้วย

Containers (คอนเทนเนอร์)

  • Sequence containers: vector, deque, list
  • Associative containers: set, multiset, map, multimap, hash_set, hash_map ฯลฯ
  • Container adaptors: queue, priority_queue, stack

Iterators (อิเทอเรเตอร์)

ออบเจ็กต์สำหรับ traverse container มี 5 ประเภท: input, output, forward, bidirectional, random access

Algorithms (อัลกอริทึม)

ฟังก์ชันสำหรับทำงานบน range ของ elements เช่น sort, binary_search, min_element ทำงานกับทุกชนิดข้อมูลที่รองรับ template

C++ Standard Library

รวม classes และ functions ที่เป็นส่วนของ ISO C++ Standard เอง ประกอบด้วย:

  • Streams: fstream, stringstream ฯลฯ
  • Containers: (รวม STL containers ด้วย)
  • General libraries: algorithm, chrono, iterator, memory ฯลฯ
  • Numerics library: complex, random ฯลฯ
  • Threading: รองรับ concurrency (C++11+)
  • C Standard Library: header แบบ C เช่น ctime (จาก time.h)