最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++內(nèi)存泄漏檢測(cè)和解決方法小結(jié)

 更新時(shí)間:2025年01月16日 09:57:25   作者:威哥愛(ài)編程(馬劍威)  
內(nèi)存泄露在編程中是常見(jiàn)的一種問(wèn)題,一但程序發(fā)生內(nèi)存泄露問(wèn)題,將導(dǎo)致程序崩潰無(wú)法運(yùn)行,內(nèi)存泄漏是指程序在運(yùn)行過(guò)程中,由于疏忽或錯(cuò)誤導(dǎo)致已分配的內(nèi)存空間無(wú)法被正確釋放,本文給大家就介紹了C++中內(nèi)存泄漏如何檢測(cè)和解決,需要的朋友可以參考下

內(nèi)存泄漏的定義

內(nèi)存泄漏是指程序在運(yùn)行過(guò)程中,由于疏忽或錯(cuò)誤導(dǎo)致已分配的內(nèi)存空間無(wú)法被正確釋放,使得這部分內(nèi)存一直被占用而無(wú)法被 操作系統(tǒng)回收再利用的現(xiàn)象。在 C++ 等編程語(yǔ)言中,如果使用 new 或 malloc 等動(dòng)態(tài)內(nèi)存分配操作,但忘記使用 delete 或 free 來(lái)釋放內(nèi)存,就可能會(huì)導(dǎo)致內(nèi)存泄漏。

內(nèi)存泄漏的危害

  • 隨著程序運(yùn)行時(shí)間的增長(zhǎng),可用內(nèi)存會(huì)逐漸減少,可能導(dǎo)致系統(tǒng)性能下降,程序響應(yīng)速度變慢。
  • 最終可能會(huì)耗盡系統(tǒng)的內(nèi)存資源,使程序崩潰或?qū)е抡麄€(gè)系統(tǒng)出現(xiàn)故障。

檢測(cè)內(nèi)存泄漏的方法

  1. 手動(dòng)檢查代碼
    • 仔細(xì)審查代碼中使用 new、new[]、malloc 等動(dòng)態(tài)內(nèi)存分配的部分,確保在不再使用內(nèi)存時(shí),有相應(yīng)的 delete、delete[] 或 free 操作。
    • 注意程序中的異常處理,確保在異常發(fā)生時(shí),分配的內(nèi)存也能被正確釋放。
    • 對(duì)于復(fù)雜的程序,這種方法可能比較困難,因?yàn)閮?nèi)存泄漏可能是由多種因素引起的。
  2. 使用工具
    • Valgrind
      • 這是一個(gè)強(qiáng)大的開(kāi)源工具,主要用于 Linux 平臺(tái),可檢測(cè) C、C++ 程序中的內(nèi)存泄漏等問(wèn)題。
      • 例如,在命令行中使用 valgrind --leak-check=full./your_program 運(yùn)行程序,它會(huì)生成詳細(xì)的內(nèi)存使用報(bào)告,指出哪些內(nèi)存沒(méi)有被正確釋放。
    • AddressSanitizer
      • 這是一個(gè)編譯器工具,集成在 GCC 和 Clang 等編譯器中,可用于檢測(cè)多種內(nèi)存錯(cuò)誤,包括內(nèi)存泄漏。
      • 可以在編譯時(shí)添加 -fsanitize=address 選項(xiàng),如 g++ -fsanitize=address -g your_program.cpp -o your_program。運(yùn)行程序時(shí),會(huì)輸出有關(guān)內(nèi)存錯(cuò)誤的信息。
    • Visual Studio 調(diào)試器
      • 在 Windows 平臺(tái)上,Visual Studio 提供了內(nèi)存診斷工具。
      • 在調(diào)試程序時(shí),可使用“診斷工具”窗口查看內(nèi)存使用情況,它可以檢測(cè)內(nèi)存泄漏,并提供詳細(xì)的信息。

解決內(nèi)存泄漏的方法

  1. 正確使用內(nèi)存管理操作符
    • 在 C++ 中,確保使用 new 和 delete 成對(duì)出現(xiàn),使用 new[] 和 delete[] 成對(duì)出現(xiàn)。
    • 示例:
#include <iostream>

int main() {
    int* ptr = new int;  // 分配內(nèi)存
    // 使用 ptr 指針
    delete ptr;  // 釋放內(nèi)存
    return 0;
}
  • 對(duì)于 C,使用 malloc 和 free 時(shí),也應(yīng)確保它們的正確使用:
#include <stdlib.h>
#include <stdio.h>

int main() {
    int* ptr = (int*)malloc(sizeof(int));  // 分配內(nèi)存
    if (ptr == NULL) {  // 檢查分配是否成功
        perror("malloc failed");
        return 1;
    }
    // 使用 ptr 指針
    free(ptr);  // 釋放內(nèi)存
    return 0;
}
  • 使用智能指針
  • 在 C++ 中,使用智能指針(如 std::unique_ptrstd::shared_ptr、std::weak_ptr)可以自動(dòng)管理內(nèi)存,避免手動(dòng)釋放內(nèi)存的麻煩和可能的遺漏。

  • 示例:

#include <iostream>
#include <memory>

int main() {
    std::unique_ptr<int> ptr = std::make_unique<int>(42);  // 使用 unique_ptr 自動(dòng)管理內(nèi)存
    // 不需要手動(dòng) delete
    return 0;
}
  • std::unique_ptr 會(huì)在其析構(gòu)函數(shù)中自動(dòng)釋放所指向的內(nèi)存,無(wú)需顯式調(diào)用 delete。
  1. 使用 RAII(Resource Acquisition Is Initialization)原則
    • 將資源的獲取和釋放封裝在類(lèi)的構(gòu)造函數(shù)和析構(gòu)函數(shù)中,利用對(duì)象的生命周期來(lái)管理資源。
    • 示例:
#include <iostream>

class Resource {
private:
    int* data;
public:
    Resource() {
        data = new int[100];  // 在構(gòu)造函數(shù)中分配資源
    }
    ~Resource() {
        delete[] data;  // 在析構(gòu)函數(shù)中釋放資源
    }
};

int main() {
    Resource r;  // 當(dāng) r 離開(kāi)作用域時(shí),析構(gòu)函數(shù)會(huì)自動(dòng)調(diào)用,釋放資源
    return 0;
}
  1. 內(nèi)存池技術(shù)

    • 對(duì)于頻繁的內(nèi)存分配和釋放操作,可以使用內(nèi)存池來(lái)提高性能和避免內(nèi)存碎片。
    • 內(nèi)存池在程序啟動(dòng)時(shí)分配一塊較大的內(nèi)存,需要內(nèi)存時(shí)從池中獲取,釋放時(shí)將內(nèi)存歸還到池中,避免了頻繁調(diào)用系統(tǒng)的內(nèi)存分配和釋放函數(shù)。
  2. 避免循環(huán)引用

    • 在使用智能指針時(shí),要注意避免循環(huán)引用,特別是使用 std::shared_ptr 時(shí)。
    • 示例:
#include <iostream>
#include <memory>

class A;
class B;

class A {
public:
    std::shared_ptr<B> b_ptr;
    ~A() {
        std::cout << "A's destructor called" << std::endl;
    }
};

class B {
public:
    std::shared_ptr<A> a_ptr;
    ~B() {
        std::cout << "B's destructor called" << std::endl;
    }
};

int main() {
    std::shared_ptr<A> a = std::make_shared<A>();
    std::shared_ptr<B> b = std::make_shared<B>();
    a->b_ptr = b;
    b->a_ptr = a;  // 循環(huán)引用,會(huì)導(dǎo)致內(nèi)存泄漏
    return 0;
}
  • 可以使用 std::weak_ptr 來(lái)打破循環(huán)引用:
#include <iostream>
#include <memory>

class A;
class B;

class A {
public:
    std::shared_ptr<B> b_ptr;
    ~A() {
        std::cout << "A's destructor called" << std::endl;
    }
};

class B {
public:
    std::weak_ptr<A> a_ptr;  // 使用 weak_ptr 避免循環(huán)引用
    ~B() {
        std::cout << "B's destructor called" << std::endl;
    }
};

int main() {
    std::shared_ptr<A> a = std::make_shared<A>();
    std::shared_ptr<B> b = std::make_shared<B>();
    a->b_ptr = b;
    b->a_ptr = a;
    return 0;
}

在這個(gè)修改后的例子中,B 類(lèi)中的 a_ptr 被修改為 std::weak_ptr,避免了循環(huán)引用,使得 A 和 B 的對(duì)象在不再被引用時(shí)可以正確地被銷(xiāo)毀。

通過(guò)上述方法,可以有效地檢測(cè)和解決內(nèi)存泄漏問(wèn)題,確保程序的健壯性和性能。

有哪些常見(jiàn)的情況會(huì)導(dǎo)致內(nèi)存泄漏?

以下是一些常見(jiàn)的會(huì)導(dǎo)致內(nèi)存泄漏的情況:

1. 忘記釋放動(dòng)態(tài)分配的內(nèi)存

在使用 new、new[](C++)或 malloc、calloc、realloc(C)等分配內(nèi)存后,忘記使用相應(yīng)的 delete、delete[](C++)或 free(C)釋放內(nèi)存。

// C++ 示例
void func() {
    int* ptr = new int;
    // 忘記使用 delete ptr;
}
// C 示例
void func() {
    int* ptr = (int*)malloc(sizeof(int));
    // 忘記使用 free(ptr);
}

在上述函數(shù)中,分配了內(nèi)存但沒(méi)有釋放,當(dāng)函數(shù)結(jié)束時(shí),該內(nèi)存仍然被占用,從而導(dǎo)致內(nèi)存泄漏。

2. 異常導(dǎo)致內(nèi)存泄漏

當(dāng)程序中發(fā)生異常時(shí),如果在異常發(fā)生前分配了內(nèi)存但還沒(méi)有釋放,而異常處理中又沒(méi)有正確處理該內(nèi)存釋放,就會(huì)導(dǎo)致內(nèi)存泄漏。

#include <iostream>
#include <stdexcept>

void func() {
    int* ptr = new int;
    try {
        // 拋出異常
        throw std::runtime_error("Something went wrong");
    } catch (const std::exception& e) {
        std::cerr << e.what() << std::endl;
        // 沒(méi)有釋放 ptr 導(dǎo)致內(nèi)存泄漏
    }
}

正確的做法是在異常處理中確保釋放內(nèi)存:

#include <iostream>
#include <stdexcept>

void func() {
    int* ptr = new int;
    try {
        // 拋出異常
        throw std::runtime_error("Something went wrong");
    } catch (const std::exception& e) {
        std::cerr << e.what() << std::endl;
    }
    delete ptr;  // 釋放內(nèi)存
}

3. 容器中的指針沒(méi)有正確釋放

當(dāng)使用容器存儲(chǔ)指針,并且容器被銷(xiāo)毀時(shí),如果沒(méi)有正確刪除指針?biāo)赶虻膬?nèi)存,就會(huì)導(dǎo)致內(nèi)存泄漏。

#include <iostream>
#include <vector>

int main() {
    std::vector<int*> vec;
    for (int i = 0; i < 10; ++i) {
        int* ptr = new int(i);
        vec.push_back(ptr);
    }
    // 容器銷(xiāo)毀時(shí),沒(méi)有釋放存儲(chǔ)的指針指向的內(nèi)存
    return 0;
}

應(yīng)該在容器銷(xiāo)毀前手動(dòng)釋放存儲(chǔ)的指針指向的內(nèi)存:

#include <iostream>
#include <vector>

int main() {
    std::vector<int*> vec;
    for (int i = 0; i < 10; ++i) {
        int* ptr = new int(i);
        vec.push_back(ptr);
    }
    for (int* ptr : vec) {
        delete ptr;
    }
    return 0;
}

4. 循環(huán)引用導(dǎo)致的內(nèi)存泄漏

在使用智能指針時(shí),如果出現(xiàn)循環(huán)引用,可能會(huì)導(dǎo)致內(nèi)存無(wú)法釋放。

#include <iostream>
#include <memory>

class A;
class B;

class A {
public:
    std::shared_ptr<B> b_ptr;
};

class B {
public:
    std::shared_ptr<A> a_ptr;
};

int main() {
    std::shared_ptr<A> a = std::make_shared<A>();
    std::shared_ptr<B> b = std::make_shared<B>();
    a->b_ptr = b;
    b->a_ptr = a;
    // 當(dāng) main 函數(shù)結(jié)束時(shí),a 和 b 相互引用,無(wú)法釋放內(nèi)存
    return 0;
}

解決方法是使用 std::weak_ptr 打破循環(huán)引用:

#include <iostream>
#include <memory>

class A;
class B;

class A {
public:
    std::shared_ptr<B> b_ptr;
};

class B {
public:
    std::weak_ptr<A> a_ptr;
};

int main() {
    std::shared_ptr<A> a = std::make_shared<A>();
    std::shared_ptr<B> b = std::make_shared<B>();
    a->b_ptr = b;
    b->a_ptr = a;
    return 0;
}

5. 錯(cuò)誤使用全局或靜態(tài)變量

如果全局或靜態(tài)變量中存儲(chǔ)了動(dòng)態(tài)分配的指針,并且沒(méi)有正確釋放,可能會(huì)導(dǎo)致內(nèi)存泄漏。

#include <iostream>

class MyClass {
public:
    int* data;
    MyClass() {
        data = new int[100];
    }
};

MyClass globalObj;  // 全局對(duì)象

int main() {
    // 程序結(jié)束時(shí),沒(méi)有釋放 globalObj.data 導(dǎo)致內(nèi)存泄漏
    return 0;
}

可以在全局對(duì)象的析構(gòu)函數(shù)中釋放內(nèi)存:

#include <iostream>

class MyClass {
public:
    int* data;
    MyClass() {
        data = new int[100];
    }
    ~MyClass() {
        delete[] data;
    }
};

MyClass globalObj;  // 全局對(duì)象

int main() {
    return 0;
}

6. 未關(guān)閉文件句柄或資源

雖然不是直接的內(nèi)存泄漏,但文件句柄或其他系統(tǒng)資源的泄漏可能會(huì)間接影響內(nèi)存使用。例如,打開(kāi)文件或網(wǎng)絡(luò)連接后沒(méi)有關(guān)閉,會(huì)導(dǎo)致資源耗盡,進(jìn)而影響內(nèi)存。

#include <iostream>
#include <fstream>

int main() {
    std::ofstream file("example.txt");
    // 忘記使用 file.close();
    return 0;
}

正確的做法是:

#include <iostream>
#include <fstream>

int main() {
    std::ofstream file("example.txt");
    // 操作文件
    file.close();
    return 0;
}

通過(guò)避免以上常見(jiàn)情況,可以顯著減少程序中內(nèi)存泄漏的可能性,提高程序的性能和穩(wěn)定性。

如何使用智能指針來(lái)避免內(nèi)存泄漏?

以下是使用智能指針來(lái)避免內(nèi)存泄漏的詳細(xì)說(shuō)明:

1. std::unique_ptr

  • 特點(diǎn)
    • std::unique_ptr 是獨(dú)占所有權(quán)的智能指針,同一時(shí)間只能有一個(gè) std::unique_ptr 擁有對(duì)某個(gè)對(duì)象的所有權(quán)。
    • 當(dāng) std::unique_ptr 被銷(xiāo)毀時(shí),它所指向的對(duì)象會(huì)自動(dòng)被刪除。
    • 不能復(fù)制 std::unique_ptr,但可以移動(dòng)它。
  • 示例代碼
#include <iostream>
#include <memory>

class MyClass {
public:
    MyClass() {
        std::cout << "MyClass constructor called" << std::endl;
    }
    ~MyClass() {
        std::cout << "MyClass destructor called" << std::endl;
    }
    void print() {
        std::cout << "Hello from MyClass" << std::endl;
    }
};

int main() {
    // 使用 std::make_unique 創(chuàng)建 std::unique_ptr
    std::unique_ptr<MyClass> ptr = std::make_unique<MyClass>(); 
    ptr->print();
    // 當(dāng) ptr 離開(kāi) main 函數(shù)的作用域時(shí),它會(huì)自動(dòng)調(diào)用 MyClass 的析構(gòu)函數(shù)
    return 0;
}
  • 代碼解釋
    • std::make_unique<MyClass>() 用于創(chuàng)建一個(gè) MyClass 對(duì)象,并將其存儲(chǔ)在 std::unique_ptr 中。
    • ptr->print(); 調(diào)用 MyClass 對(duì)象的 print 方法,證明對(duì)象正常使用。
    • 當(dāng) ptr 超出 main 函數(shù)的范圍時(shí),MyClass 的析構(gòu)函數(shù)會(huì)自動(dòng)調(diào)用,無(wú)需手動(dòng)調(diào)用 delete

2. std::shared_ptr

  • 特點(diǎn)
    • std::shared_ptr 允許多個(gè)智能指針共享對(duì)同一對(duì)象的所有權(quán)。
    • 它使用引用計(jì)數(shù)機(jī)制,當(dāng)最后一個(gè) std::shared_ptr 被銷(xiāo)毀時(shí),對(duì)象會(huì)被刪除。
    • 可以復(fù)制 std::shared_ptr,并且它們都指向同一個(gè)對(duì)象。
  • 示例代碼
#include <iostream>
#include <memory>

class MyClass {
public:
    MyClass() {
        std::cout << "MyClass constructor called" << std::endl;
    }
    ~MyClass() {
        std::cout << "MyClass destructor called" << std::endl;
    }
    void print() {
        std::cout << "Hello from MyClass" << std::endl;
    }
};

int main() {
    // 使用 std::make_shared 創(chuàng)建 std::shared_ptr
    std::shared_ptr<MyClass> ptr1 = std::make_shared<MyClass>(); 
    std::shared_ptr<MyClass> ptr2 = ptr1; 
    ptr1->print();
    ptr2->print();
    // 當(dāng) ptr1 和 ptr2 都超出作用域時(shí),MyClass 的析構(gòu)函數(shù)會(huì)被調(diào)用
    return 0;
}
  • 代碼解釋
    • std::make_shared<MyClass>() 創(chuàng)建一個(gè) MyClass 對(duì)象并存儲(chǔ)在 std::shared_ptr 中。
    • std::shared_ptr<MyClass> ptr2 = ptr1; 讓 ptr2 共享 ptr1 所指向?qū)ο蟮乃袡?quán),引用計(jì)數(shù)加 1。
    • 當(dāng) ptr1 和 ptr2 都超出作用域時(shí),引用計(jì)數(shù)變?yōu)?0,MyClass 的析構(gòu)函數(shù)會(huì)自動(dòng)調(diào)用。

3. std::weak_ptr

  • 特點(diǎn)
    • std::weak_ptr 是一種弱引用,它不會(huì)增加 std::shared_ptr 的引用計(jì)數(shù)。
    • 通常用于解決 std::shared_ptr 之間的循環(huán)引用問(wèn)題。
  • 示例代碼
#include <iostream>
#include <memory>

class A;
class B;

class A {
public:
    std::shared_ptr<B> b_ptr;
    ~A() {
        std::cout << "A's destructor called" << std::endl;
    }
};

class B {
public:
    std::weak_ptr<A> a_ptr;
    ~B() {
        std::cout << "B's destructor called" << std::endl;
    }
};

int main() {
    std::shared_ptr<A> a = std::make_shared<A>();
    std::shared_ptr<B> b = std::make_shared<B>();
    a->b_ptr = b;
    b->a_ptr = a;
    // 當(dāng) main 函數(shù)結(jié)束時(shí),不會(huì)因?yàn)檠h(huán)引用而導(dǎo)致內(nèi)存泄漏
    return 0;
}
  • 代碼解釋
    • std::make_shared<A>() 和 std::make_shared<B>() 分別創(chuàng)建 A 和 B 的對(duì)象并存儲(chǔ)在 std::shared_ptr 中。
    • a->b_ptr = b; 和 b->a_ptr = a; 會(huì)造成循環(huán)引用,如果 a_ptr 也是 std::shared_ptr,則會(huì)導(dǎo)致內(nèi)存泄漏。
    • 但使用 std::weak_ptr 不會(huì)增加引用計(jì)數(shù),當(dāng) main 函數(shù)結(jié)束時(shí),a 和 b 的析構(gòu)函數(shù)會(huì)被正確調(diào)用,因?yàn)樗鼈儾粫?huì)相互保持對(duì)方的生命周期。

小結(jié)

  • 使用 std::unique_ptr 可以確保獨(dú)占資源的自動(dòng)釋放,適用于大多數(shù)不需要共享資源的情況。
  • std::shared_ptr 適用于需要共享資源的情況,但要注意避免循環(huán)引用,否則可能導(dǎo)致內(nèi)存泄漏。
  • std::weak_ptr 可用于解決 std::shared_ptr 引起的循環(huán)引用問(wèn)題,它不會(huì)影響對(duì)象的生命周期,但可以檢查對(duì)象是否仍然存在。

通過(guò)使用這些智能指針,可以避免手動(dòng)管理內(nèi)存時(shí)可能出現(xiàn)的忘記釋放內(nèi)存、異常導(dǎo)致無(wú)法釋放內(nèi)存等問(wèn)題,從而避免內(nèi)存泄漏。

最后

以上就是C++內(nèi)存泄漏檢測(cè)和解決方法的詳細(xì)內(nèi)容,更多關(guān)于C++內(nèi)存泄漏檢測(cè)和解決的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 老生常談C語(yǔ)言中指針的使用

    老生常談C語(yǔ)言中指針的使用

    這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言中指針的使用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-02-02
  • Visual Studio 2022最新版安裝教程(圖文詳解)

    Visual Studio 2022最新版安裝教程(圖文詳解)

    本文主要介紹了Visual Studio 2022最新版安裝教程,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • C++中bitset位圖介紹及模擬實(shí)現(xiàn)

    C++中bitset位圖介紹及模擬實(shí)現(xiàn)

    位圖就是用每一位來(lái)存放某種狀態(tài),適用于海量數(shù)據(jù),本文就介紹一下C++中bitset位圖介紹及模擬實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-07-07
  • C++實(shí)現(xiàn)假裝藍(lán)屏整蠱小程序

    C++實(shí)現(xiàn)假裝藍(lán)屏整蠱小程序

    因?yàn)楣ぷ鞯男枰?,有時(shí)候我們離開(kāi)時(shí)并不想讓別人看到我們電腦的內(nèi)容,所以本文為大家分享了一個(gè)基于C++實(shí)現(xiàn)的假裝藍(lán)屏的小程序,需要的可以參考下
    2023-06-06
  • C語(yǔ)言詳細(xì)分析講解內(nèi)存管理malloc realloc free calloc函數(shù)的使用

    C語(yǔ)言詳細(xì)分析講解內(nèi)存管理malloc realloc free calloc函數(shù)的使用

    C語(yǔ)言?xún)?nèi)存管理相關(guān)的函數(shù)主要有realloc、calloc、malloc、free等,下面這篇文章主要給大家介紹了關(guān)于C語(yǔ)言?xún)?nèi)存管理realloc、calloc、malloc、free函數(shù)的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • 如何將C++源程序改寫(xiě)為C語(yǔ)言

    如何將C++源程序改寫(xiě)為C語(yǔ)言

    C++中主要的與C的區(qū)別最大而且最常用的特性及修改方法,接下來(lái)我們一起來(lái)學(xué)習(xí)他們吧
    2021-08-08
  • C++設(shè)計(jì)模式之裝飾模式(Decorator)

    C++設(shè)計(jì)模式之裝飾模式(Decorator)

    這篇文章主要為大家詳細(xì)介紹了C++設(shè)計(jì)模式之裝飾模式Decorator的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • tc編譯的dos程序和vc編譯的win32控制臺(tái)程序的異同

    tc編譯的dos程序和vc編譯的win32控制臺(tái)程序的異同

    tc編譯的dos程序和vc編譯的win32控制臺(tái)程序的異同...
    2007-08-08
  • Visual Studio Code (VSCode) 配置搭建 C/C++ 開(kāi)發(fā)編譯環(huán)境的流程

    Visual Studio Code (VSCode) 配置搭建 C/C++ 開(kāi)發(fā)編譯環(huán)境的流程

    記得N年前剛開(kāi)始接觸編程時(shí),使用的是Visual C++6.0,下面這個(gè)可愛(ài)的圖標(biāo)很多人一定很熟悉。不過(guò)今天想嘗鮮新的工具 Visual Studio Code 來(lái)搭建C/C++開(kāi)發(fā)環(huán)境,感興趣的朋友一起看看吧
    2021-09-09
  • c++非變易算法-stl算法

    c++非變易算法-stl算法

    本文主要介紹了C++ STL算法庫(kù)中的非變易算法,是一些原則上不會(huì)變更操作數(shù)據(jù)的算法,包括:逐個(gè)查找算法、元素搜索算法、元素統(tǒng)計(jì)算法、序列匹配算法、子序列搜索算法、這些函數(shù)均包含于<algorithm>頭文件,本文給出的所有代碼在VS2010中編譯運(yùn)行通過(guò)
    2014-03-03

最新評(píng)論

永年县| 姚安县| 黎平县| 三河市| 米林县| 香格里拉县| 田林县| 海原县| 旅游| 财经| 定陶县| 库车县| 苍梧县| 枝江市| 仁布县| 藁城市| 四川省| 贺兰县| 彭阳县| 筠连县| 冕宁县| 定结县| 峡江县| 龙南县| 阳原县| 五寨县| 开江县| 金坛市| 克什克腾旗| 通州市| 云龙县| 新沂市| 武平县| 锦屏县| 华池县| 旺苍县| 景宁| 营口市| 雷州市| 桃源县| 山东省|