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

Hem*_*dra 6 c++ c++11 visual-studio-2012

我编写了一个程序,在相应的分隔符出现时拆分字符串.但是发生了一个不同的错误:

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
Run Code Online (Sandbox Code Playgroud)

我在开发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;

}
Run Code Online (Sandbox Code Playgroud)

我甚至尝试删除标题 并将main()函数更改为int main()和int main(void).但是在visual studio中也会出现同样的错误.请有人帮帮我.

mpi*_*tek 15

CrtDbgReportCRT的调试版本(C运行时库)中定义.您最有可能构建调试配置,但链接到CRT的发行版本.

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

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

#define _DEBUG
#include <string>
Run Code Online (Sandbox Code Playgroud)

并且即使选择了正确的运行时库,在发布中构建示例也会导致此问题.

  • 谢谢。我将运行时库更改为 MTd。有效。 (2认同)