Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

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

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

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

My Program:

#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,
 next line
 as the
 delimiter: ";
string delimiter = "
";
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;

}

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...