Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++
C++
  1. การจัดเรียงลำดับจากมากไปน้อยใน Map และ Multimap ของ C++ STL

    โดยทั่วไป พฤติกรรมเริ่มต้นของ map และ multimap คือการจัดเก็บข้อมูลในลำดับจากน้อยไปมาก (ascending order) แต่เราสามารถจัดเก็บในลำดับจากมากไปน้อย (descending order) ได้โดยใช้ฟังก์ชัน greater Map แบบเรียงลำดับจากมากไปน้อย ฟังก์ชันที่ใช้ในตัวอย่าง m::find() – คืนค่า iterator ไปยังองค์ประกอบที่มีคีย์ b

  2. emplace vs insert in C++ STL

    emplace operation หลีกเลี่ยงการ copy object ที่ไม่จำเป็น และทำ insertion ได้มีประสิทธิภาพมากกว่า insert operation Insert operation รับ reference ไปยัง object Algorithm Begin Declare set. Use emplace() to insert pair. Use insert() to insert pair by using emplace(). Print the set. End ตัวอย่างโค้ด #i

  3. How to remove an item from a C++ STL vector with a certain value?

    Erase function ใช้เพื่อลบ item จาก C++ STL vector ด้วยค่าที่กำหนด Algorithm Begin Declare vector v and iterator it to the vector. Initialize the vector. Erase() function is used to remove item from end. Print the remaining elements. End. ตัวอย่างโค้ด #include <iostream> #include <vector>

  4. Insertion and Deletion in STL Set C++

    Insertion (การแทรก) Insertion ใน STL set สามารถทำได้โดย insert() และ emplace() operation Insert(): Insert() ใช้เพื่อแทรก elements ลงใน set Insert operation รับ reference ไปยัง object List of functions are used: st.size() = Returns the size of set. st.insert() = It is used to insert elements to the

  5. iswalnum() function in C++ STL

    iswalnum() function ใน C++ STL ตรวจสอบว่า wide character ที่กำหนดเป็น alphanumeric character หรือไม่ กล่าวคือ ตัวเลข (0-9), ตัวพิมพ์ใหญ่ (A-Z), ตัวพิมพ์เล็ก (a-z) หรือ alphanumeric character อื่นๆ Algorithm Begin Initializes the characters. Call function iswalnum(c1) to check whether it is alphanum

  6. iswalpha() function in C++ STL

    iswalpha() function ใน C++ STL ใช้ตรวจสอบว่า wide character ที่กำหนดเป็นตัวอักษรหรือไม่ Algorithm Begin Initializes the strings. Call function iswalpha(str) to check whether it contains alphabet or not. If it contains alphabet, then value will be returned otherwise zero will be returned. End ตัวอย่

  7. lldiv() function in C++ STL

    lldiv() function ใน C++ STL ให้ผลลัพธ์ของ quotient (ผลหาร) และ remainder (เศษ) ของการหารสองจำนวน Algorithm Begin Take two long type numbers as input. Call function lldiv(). Print the quotient and remainder. End. ตัวอย่างโค้ด #include <cstdlib> #include <iostream> using namespace std; in

  8. multiset insert() function in C++ STL

    multiset insert() function ใน C++ STL ใช้สำหรับแทรก elements ลงใน multiset container จากตำแหน่งหนึ่งไปอีกตำแหน่งหนึ่งจาก multiset หนึ่งไปยัง multiset อื่น List of functions used: ms.size() = Returns the size of multiset. ms.insert() = It is used to insert elements to the multiset. ตัวอย่างโค้ด #i

  9. negate function in C++ STL

    Negate function ใช้เพื่อ negate ค่าที่กำหนด เช่น เปลี่ยนเครื่องหมายของค่า เปลี่ยนค่าลบเป็นบวกและในทางกลับกัน Function prototype: function transform(a_begin, a_end, a1_begin, negate()): a_begin = lower bound of the array. a_end = upper bound of the array. a1_end = Lower bound of the seco

  10. C++ Program to Implement String Matching Using Vectors

    นี่คือ string matching method อีกวิธีหนึ่ง ในแนวทางนี้ เราค้นหา substring โดยใช้ vectors ใน C++ เราสามารถสร้าง vectors ได้ง่ายด้วย standard library เราเอา main string และ string ที่จะค้นหาเป็น vector แล้วค้นหาใน main string เมื่อเจอ match หนึ่งครั้ง ฟังก์ชันจะคืนค่าที่อยู่ และลบออกจาก main string ด

  11. Difference between string and char[] types in C++

    ในส่วนนี้ เราจะดูความแตกต่างระหว่าง string และ char[] ใน C++ char[] คือ array ของ characters โดยพื้นฐาน ดังนั้นมีคุณสมบัติของ array บางอย่าง คุณสมบัติเหล่านี้ระบุด้านล่าง ถ้า char[] ถูกจัดสรรในส่วน stack จะใช้พื้นที่ 256 bytes เสมอ ไม่ขึ้นกับขนาดของข้อความ ถ้าเราใช้ malloc() หรือ calloc() เพื่อจัด

  12. Differences between C++ string == and compare()?

    ใน C++ เราสามารถเปรียบเทียบสตริงสองตัวได้โดยใช้ compare() function และ == operator คำถามคือ ทำไมถึงมีสองวิธีต่างกัน? มีความแตกต่างหรือไม่? มีความแตกต่างพื้นฐานบางอย่างระหว่าง compare() และ == operator ใน C++ ตัวดำเนินการ == ถูก overload สำหรับ string เพื่อตรวจสอบว่าสตริงทั้งสองเหมือนกันหรือไม่ ถ้าเ

  13. How to convert a std::string to const char* or char* in C++?

    ในส่วนนี้ เราจะดูวิธีแปลง C++ string (std::string) เป็น const char* หรือ char* รูปแบบเหล่านี้เป็น C-style strings เรามีฟังก์ชันชื่อ c_str() ฟังก์ชันนี้จะช่วยทำภารกิจนี้ มันคืนค่า pointer ไปยัง array ที่มี null-terminated sequence of characters (เช่น C-string) ที่แสดงค่าปัจจุบันของ string object การ

  14. How to convert an enum type variable to a string in C++?

    ที่นี่เราจะดูวิธีแปลง enum type data เป็น string ใน C++ ไม่มีฟังก์ชันโดยตรงที่ทำได้ แต่เราสามารถสร้างฟังก์ชันของตัวเองเพื่อแปลง enum เป็น string ได้ เราจะสร้างฟังก์ชันที่รับ enum value เป็น argument และเรา return enum names เป็น string จากฟังก์ชันนั้นด้วยตนเอง ตัวอย่างโค้ด #include <iostream>

  15. How to convert std::string to lower case in C++?

    ในส่วนนี้ เราจะดูวิธีแปลงตัวอักษรทั้งหมดของ C++ string ให้เป็นตัวพิมพ์เล็ก (lowercase) เพื่อทำสิ่งนี้เราต้องใช้ transform function ฟังก์ชัน transform นี้อยู่ใน algorithm library Transform function รับ beginning pointer ของ string และ ending pointer ของ string มันยังรับ beginning ของ string เพื่อเก็

  16. How to map C++ enums to strings? (การแมป enum ไปยัง string ใน C++)

    ที่นี่เราจะดูวิธี map enum type data ไปยัง string ใน C++ ไม่มีฟังก์ชันโดยตรงที่ทำได้ แต่เราสามารถสร้างฟังก์ชันของตัวเองเพื่อแปลง enum เป็น string ได้ เราจะสร้างฟังก์ชันที่รับ enum value เป็น argument และเรา return enum names เป็น string จากฟังก์ชันนั้นด้วยตนเอง ตัวอย่างโค้ด #include <iostream>

  17. วิธี reverse string อย่างรวดเร็วใน C++

    ในส่วนนี้ เราจะดูวิธี reverse string อย่างรวดเร็วโดยใช้ C++ สำหรับการ reverse มี built-in function ใน algorithm library ชื่อ reverse() ฟังก์ชันนี้รับ beginning และ ending pointer ของ container แล้ว reverse elements Input: A number string Hello World Output: dlroW olleH Algorithm Step 1: Take a stri

  18. วิธีลบตัวอักษรบางตัวออกจาก string ใน C++

    ในส่วนนี้ เราจะดูวิธีลบตัวอักษรบางตัวออกจาก string ใน C++ ใน C++ เราสามารถทำได้ง่ายมากโดยใช้ erase() และ remove() function ฟังก์ชัน remove รับ starting และ ending address ของ string และ character ที่จะถูกลบ Input: A number string ABAABACCABA Output: BBCCB Algorithm Step 1: Take a string Step 2: Rem

  19. string at() function in C++

    ในส่วนนี้ เราจะดูว่า at() function ใน C++ คืออะไร ฟังก์ชัน at() ใช้เพื่อเข้าถึง character ที่ตำแหน่งที่กำหนด ในโปรแกรมนี้ เราจะ iterate ทุก character โดยใช้ at() function และพิมพ์พวกมันในบรรทัดต่างๆ ตัวอย่างโค้ด #include<iostream> using namespace std; main() { string my_str = Hello World;

  20. The most elegant way to iterate the words of a string using C++

    ไม่มีวิธีขยันเดียวที่สวยงามที่สุดในการ iterate words ของ C/C++ string วิธีที่อ่านง่ายที่สุดอาจถูกเรียกว่าสวยงามที่สุดสำหรับบางคน ในขณะที่ประสิทธิภาพสูงสุดสำหรับอีกบางคน ผมได้รายการ 2 วิธีที่คุณสามารถใช้เพื่อบรรลุเป้าหมายนี้ วิธีแรกคือการใช้ stringstream เพื่ออ่านคำที่คั่นด้วย spaces วิธีนี้มีข้อจำก

Total 6007 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:36/301  20-คอมพิวเตอร์/Page Goto:1 30 31 32 33 34 35 36 37 38 39 40 41 42