错误:LNK 2019:Visual Studio中未解析的外部符号_imp_CrtDbgReportw

错误:LNK 2019:Visual Studio中未解析的外部符号_imp_CrtDbgReportw

问题描述:

我编写了一个程序,当相应的定界符出现时,该程序将拆分字符串。但是发生了另一种错误,例如:

I have written a program that splits a string when the respective delimiter occurs. But a different error is occurring like :


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 " (??D?$_String_const_iterator@V?$_String_val@U?$_Simple_types@D@std@@@std@@@std@@QBEABDXZ)    Source.cpp Using Object_Type Input


我在 dev c ++ 中测试了相同的程序,并且运行良好,但是在Visual Studio中,这类问题不断出现。

I tested the same program in dev c++ and it is working fine but in visual studio these type of problems are raising.

我的程序:

#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 main(void)。但是在Visual Studio中也会发生相同的错误。请有人帮助我。

I even tried removing the header and changing the main() function to int main() and int main(void). But the same error occurs in visual studio. Please anyone help me.

CrtDbgReport 是在的调试版本中定义的 CRT(C运行时库)

CrtDbgReport is defined in debug version of CRT (C Run-time Library). You are most likely building debug configuration but linking against release version of CRT.

检查属性-> C / C ++->代码生成->运行时库。

Check Properties -> C/C++ -> Code Generation -> Runtime library.

其他可能性是,您正在构建发行版配置,但有一些定义导致 string 内置于调试配置中。最简单的例子是:

Other possibility is that you are building release configuration but have some define that is causing string to be built in debug configuration. The easiest example of this would be:

#define _DEBUG
#include <string>

在发行版中构建示例,即使选择了正确的运行时库也将导致此问题。

and building your example in release will cause exactly this problem even if the correct runtime library is chosen.