2017-03-15 94 views
4

我寫了一個程序,當相應的分隔符發生時分割字符串。但是,不同的錯誤發生,如:錯誤:LNK 2019:無法解析的外部符號_imp_CrtDbgReportw在Visual Studio中

Error 1 error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: char const & __thiscall std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >::operator*(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@@[email protected]@QBEABDXZ) Source.cpp Using Object_Type Input 

開發的C++測試相同的程序,它工作正常,但在Visual Studio這些類型的問題正在提高。

我的計劃:

#include <string> 
#include <iostream> 
#include<tchar.h> 
using namespace std; 

#pragma comment (lib, "ws2_32.lib") 

int _tmain(int argc, _TCHAR* argv[]) 
{ 

string s = "Enter a line of text,\n next line\n as the\n delimiter: "; 
string delimiter = "\n"; 
size_t pos = 0; 
string token; 

while ((pos = s.find(delimiter)) != std::string::npos) { 
    token = s.substr(0, pos); 
    std::cout << token << std::endl; 
    s.erase(0, pos + delimiter.length()); 
} 
std::cout << s << std::endl; 

return 0; 

} 

我甚至嘗試刪除頁眉和更改main()函數爲int main()和INT主要(無效)。但在Visual Studio中發生同樣的錯誤。請任何人幫助我。

回答

5

CrtDbgReport在調試版本CRT (C Run-time Library)中定義。您最有可能構建調試配置,但與CRT的發佈版本鏈接。

檢查屬性 - > C/C++ - >代碼生成 - >運行時庫。

其他可能性是您正在構建發佈配置,但有一些定義導致string在調試配置中生成。這樣做的最簡單的例子是:

#define _DEBUG 
#include <string> 

和建設釋放你的榜樣將導致即使選擇了正確的運行時庫正是這個問題。

+0

謝謝。我將運行時間庫改爲MTd。有效。 –

相關問題