2013-01-03 78 views
7

可能重複時:
Why does calling boost:split() give so many warnings?與升壓::分裂警告編譯

所以,這是我的代碼:

Account ParseString(string data){ 
    vector <string> fields; 
    boost::split(fields, data, boost::is_any_of("a,;")); 
    int limit = fields.size(); 
    for(int i = 0; i < limit; i++) 
     cout << fields[i] << endl; 
} 

,這就是我得到的時候試圖編譯:

d:\program files (x86)\visualstudio\vc\include\xutility(2227): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' 

我的問題是,我做錯了什麼?我能做些什麼來防止這些錯誤信息?

+2

可以禁用該警告。 –

+2

[此警告是MSVC2012中的錯誤](http://stackoverflow.com/questions/12618087/vs-11-d-scl-secure-no-warnings-in-vs-10-treated-as-errors-now )。 – rubenvb

回答

11

你沒有做錯任何事。 Visual Studio過於謹慎。在調試模式下,Visual Studio使用一種稱爲「檢查迭代器」的東西。指針也是迭代器,但檢查機制不適用於它們。因此,當使用指針調用標準庫算法時,這是boost::split所做的,它會發出此警告。

您將與這顯然安全的代碼得到同樣的警告:

int main() 
{ 
    int x[10] = {}; 
    int y[10] = {}; 
    int *a = x, *b = y; 
    std::copy(a, a+10, b); 
} 

禁用警告。這是初學者。默認情況下,爲了初學者的安全,因爲如果它默認關閉,他們將不知道如何打開它。

+0

謝謝,我可以在哪裏關掉它? :) – Theolodis

+2

@Theolodis:將'-D_SCL_SECURE_NO_WARNINGS'添加到命令行。在IDE中,您可以轉到「項目 - >屬性 - > C/C++ - >命令行」並將其添加到其他選項字段中。 –

+0

非常感謝它的作品! – Theolodis

1

你沒有做錯任何事情,如果你看看警告它似乎並不可怕:)另外我相信在這種情況下,你不需要執行任何操作。