c++ - 错误 : LNK 2019 : unresolved external symbol _imp_CrtDbgReportw in Visual Studio

标签 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

我在 dev 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;

}

我什至尝试删除 header 并将 main() 函数更改为 int main() 和 int main(void)。但是在visual studio中出现同样的错误。请任何人帮助我。

最佳答案

CrtDbgReportCRT (C Run-time Library) 的调试版本中定义.您很可能正在构建调试配置,但链接的是 CRT 的发布版本。

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

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

#define _DEBUG
#include <string>

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

关于c++ - 错误 : LNK 2019 : unresolved external symbol _imp_CrtDbgReportw in Visual Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42801276/

相关文章:

c++ - std::tie 语法不清晰

c++ - 为什么我的派生类找不到我的基类的类型别名?

c++ - 如何通过不同版本的tcp传输不同的对象

c# - 用于错误描述的 visual studio 键盘快捷键

c - fwrite() 性能远低于磁盘容量

c++ - TMP : how to generalize a Cartesian Product of Vectors?

c++ - (;;) {} 和 while(true) {} 哪个更好?

c++ - 为什么在linux信号事件中未定义静态成员的使用

c++ - boost::future .then() 继续返回 boost::future

visual-studio-2010 - 修复 "MSVCP110D.dll is missing from your computer"问题