All Questions

Tagged with
Filter by
Sorted by
Tagged with
466 votes
31 answers
375k views

Why is this program erroneously rejected by three C++ compilers?

I am having some difficulty compiling a C++ program that I've written. This program is very simple and, to the best of my knowledge, conforms to all the rules set forth in the C++ Standard. I've ...
222 votes
31 answers
729k views

Unresolved external symbol in object files [duplicate]

During coding in Visual Studio I got an unresolved external symbol error and I've got no idea what to do. I don't know what's wrong. Could you please decipher me? Where should I be looking for what ...
Novellizator's user avatar
  • 14.2k
195 votes
5 answers
158k views

What does "#pragma comment" mean?

What does #pragma comment mean in the following? #pragma comment(lib, "kernel32") #pragma comment(lib, "user32")
user198729's user avatar
  • 62.8k
163 votes
13 answers
275k views

error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

While I am running the simple code as below I have two errors as following: #include <iostream> #include <string> using namespace::std; template <class Type> class Stack { public: ...
NAIEM's user avatar
  • 1,659
163 votes
15 answers
178k views

Fatal error: "No Target Architecture" in Visual Studio

When I try to compile my c++ project using Visual Studio 2010 in either Win32 or x64 mode I get the following error: >C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(135): ...
philipvr's user avatar
  • 6,058
160 votes
9 answers
149k views

Cannot open include file 'afxres.h' in VC2010 Express

I'm trying to compile an old project using VS express 2010 but I get this error: fatal error RC1015: cannot open include file 'afxres.h'. from this code ////////////////////////////////////////////...
clamp's user avatar
  • 33.5k
158 votes
11 answers
210k views

Disable single warning error

Is there a way to disable just a single warning line in a cpp file with visual studio? For example, if I catch an exception and don't handle it, I get error 4101 (unreferenced local variable). Is ...
Cookie's user avatar
  • 12.3k
152 votes
3 answers
180k views

Explicit Return Type of Lambda

When I try and compile this code (VS2010) I am getting the following error: error C3499: a lambda that has been specified to have a void return type cannot return a value void DataFile::...
Ryan's user avatar
  • 6,562
137 votes
6 answers
224k views

LPCSTR, LPCTSTR and LPTSTR

What the difference between LPCSTR, LPCTSTR and LPTSTR? Why do we need to do this to convert a string into a LV / _ITEM structure variable pszText: LV_DISPINFO dispinfo; dispinfo.item.pszText = ...
nothingMaster's user avatar
121 votes
11 answers
111k views

Can I download the Visual C++ Command Line Compiler without Visual Studio?

As per the title. I don't want to download the entire Visual C++ installer, only "cl.exe" and the other programs required for compiling and linking C++ programs on Windows.
magnus's user avatar
  • 4,201
120 votes
24 answers
285k views

Get a file name from a path

What is the simplest way to get the file name that from a path? string filename = "C:\\MyDirectory\\MyFile.bat" In this example, I should get "MyFile". without extension.
nidhal's user avatar
  • 1,679
120 votes
3 answers
38k views

What's the fundamental difference between MFC and ATL?

Assuming I am only using them for "normal" GUI programs (no COM, no ActiveX, nothing fancy), what is the fundamental difference I will see between ATL and MFC, to help me figure out which one to use? ...
user541686's user avatar
  • 208k
118 votes
6 answers
158k views

How to call C++ function from C?

I know this. Calling C function from C++: If my application was in C++ and I had to call functions from a library written in C. Then I would have used //main.cpp extern "C" void ...
claws's user avatar
  • 53.3k
116 votes
9 answers
480k views

How to use _CRT_SECURE_NO_WARNINGS

I have a compile error in my simple MFC window application generated from wizard with several lines of code: error C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s ...
vico's user avatar
  • 17.7k
114 votes
7 answers
364k views

'uint32_t' identifier not found error

I'm porting code from Linux C to Visual C++ for windows. Visual C++ doesn't know #include <stdint.h> so I commented it out. Later, I found a lot of those 'uint32_t': identifier not found ...
kevin's user avatar
  • 13.8k
114 votes
6 answers
87k views

C++ #include and #import difference

What is the difference between #include and #import in C++?
Marius's user avatar
  • 58.4k
111 votes
5 answers
56k views

How does the Import Library work? Details?

I know this may seem quite basic to geeks. But I want to make it crystal clear. When I want to use a Win32 DLL, usually I just call the APIs like LoadLibrary() and GetProcAdderss(). But recently, I ...
smwikipedia's user avatar
  • 63.2k
108 votes
3 answers
74k views

what does __declspec(dllimport) really mean?

I saw the Qt source code like this: class Q_CORE_EXPORT QBasicAtomicInt { public: ... }; Which Q_CORE_EXPORT macro defines like below: define Q_DECL_IMPORT __declspec(dllimport) So what does ...
gemfield's user avatar
  • 3,278
103 votes
12 answers
66k views

Visual Studio support for new C / C++ standards?

I keep reading about C99 and C++11 and all these totally sweet things that are getting added to the language standard that might be nice to use someday. However, we currently languish in the land of ...
Colen's user avatar
  • 13.6k
102 votes
4 answers
462k views

How to add additional libraries to Visual Studio project?

Allergro is an open souce C++ addon library for graphics manipulation. How do I add this library to my compiler? The instructions don't work for me as I have Windows 7. I don't know if the OS matters....
Saad Masood's user avatar
  • 11.2k
102 votes
8 answers
140k views

memset() or value initialization to zero out a struct?

In Win32 API programming it's typical to use C structs with multiple fields. Usually only a couple of them have meaningful values and all others have to be zeroed out. This can be achieved in either ...
sharptooth's user avatar
  • 169k
101 votes
7 answers
161k views

What is the difference between C++ and Visual C++? [duplicate]

What is the difference between C++ and Visual C++? I know that C++ has the portability and all, so if you know C++ how is it related to Visual C++? Is Visual C++ mostly for online apps? Would Visual ...
user avatar
99 votes
5 answers
243k views

How can I insert element into beginning of vector?

I need to insert values into the beginning of a std::vector and I need other values in this vector to be pushed to further positions for example: something added to beginning of a vector and values ...
Paweł Szymkowicz's user avatar
95 votes
7 answers
145k views

LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in file.obj

I am Integrating Matlab, C and Cuda together in a project. I used Matlab mix in order to connect matlab mx function written in c with the cuda runtime library, a linking error appear about conflict in ...
Ahmed Hassan's user avatar
95 votes
1 answer
62k views

C++11 features in Visual Studio 2012

A preview version of Visual Studio 2012 (the next version after VS2010) is now available. Does anyone know what new C++11 features it supports? (I'm not in a position to try it out at the moment).
HighCommander4's user avatar
94 votes
5 answers
113k views

module unsafe for SAFESEH image C++

I am using Microsoft Visual Studio 2011 Professional Beta I am trying to run the OpenCV C++ files (http://opencv.willowgarage.com/wiki/Welcome) that I have compiled using cMake & the Visual ...
Aaron Thompson's user avatar
91 votes
8 answers
147k views

How to increment an iterator by 2?

Can anybody tell me how to increment the iterator by 2? iter++ is available - do I have to do iter+2? How can I achieve this?
Cute's user avatar
  • 13.8k
86 votes
7 answers
171k views

How to write to the Output window in Visual Studio?

Which function should I use to output text to the "Output" window in Visual Studio? I tried printf() but it doesn't show up.
clamp's user avatar
  • 33.5k
86 votes
5 answers
4k views

How is "int* ptr = int()" value initialization not illegal?

The following code (taken from here): int* ptr = int(); compiles in Visual C++ and value-initializes the pointer. How is that possible? I mean int() yields an object of type int and I can't assign ...
sharptooth's user avatar
  • 169k
86 votes
9 answers
69k views

Is it possible to force a function not to be inlined?

I want to force a little function not to be compiled as inline function even if it's very simple. I think this is useful for debug purpose. Is there any keyword to do this?
Thomson's user avatar
  • 21.1k
85 votes
7 answers
72k views

Is using #pragma warning push/pop the right way to temporarily alter warning level?

Once in a while it's difficult to write C++ code that wouldn't emit warnings at all. Having warnings enabled is however a good idea. So it is often necessary to disable warnings around some specific ...
sharptooth's user avatar
  • 169k
84 votes
11 answers
48k views

Visual Studio 2010's strange "warning LNK4042"

I've just been beaten (rather hardly) on the head by some non-trivial warning from Visual Studio 2010 (C++). The compilation gave the following output: 1 Debug\is.obj : warning LNK4042: object ...
Matthieu M.'s user avatar
82 votes
2 answers
32k views

What is the difference between the /Ox and /O2 compiler options?

Microsoft's C++ compiler (cl.exe, as included with Visual Studio) offers several optimization switches. The difference between most of them seems self-explanatory, but it's not clear to me what the ...
Cody Gray - on strike's user avatar
79 votes
4 answers
239k views

What is C# equivalent of <map> in C++? [duplicate]

I have defined a class myComplex. I need to map it to integers. In C++ I would have created a map as map<myComplex,int> first; How to do such thing in C#?
Abhash Kumar Singh's user avatar
79 votes
2 answers
36k views

Problem calling std::max

I compiled my bison-generated files in Visual Studio and got these errors: ...\position.hh(83): error C2589: '(' : illegal token on right side of '::' ...\position.hh(83): error C2059: syntax ...
Haiyang's user avatar
  • 1,527
78 votes
4 answers
132k views

error LNK2005: xxx already defined in MSVCRT.lib(MSVCR100.dll) C:\something\LIBCMT.lib(setlocal.obj)

I'm using DCMTK library for reading Dicom files (Image format used in medical image processing.) I'm having a problem in compiling this DCMTK source code. DCMTK uses some additional external libraries ...
volpack's user avatar
  • 835
78 votes
11 answers
43k views

Why is Visual C++ lacking refactor functionality?

When programming in C++ in Visual Studio 2008, why is there no functionality like that seen in the refactor menu when using C#? I use Rename constantly and you really miss it when it's not there. I'm ...
xyz's user avatar
  • 27.6k
77 votes
8 answers
85k views

GCC worth using on Windows to replace MSVC?

I currently develop in C++ on Windows, using Visual Studio 2010. After the official announcement of C++11, I have begun to use some of its features that are already available in MSVC. But, as expected,...
Nairou's user avatar
  • 3,655
76 votes
10 answers
167k views

Disabling Warnings generated via _CRT_SECURE_NO_DEPRECATE

What is the best way to disable the warnings generated via _CRT_SECURE_NO_DEPRECATE that allows them to be reinstated with ease and will work across Visual Studio versions?
grrussel's user avatar
  • 7,289
76 votes
11 answers
6k views

How bad is "if (!this)" in a C++ member function?

If I come across old code that does if (!this) return; in an app, how severe a risk is this? Is it a dangerous ticking time bomb that requires an immediate app-wide search and destroy effort, or is it ...
Crashworks's user avatar
76 votes
9 answers
27k views

Useful Add-Ins or Plug-Ins for native Visual Studio developer [closed]

There are plenty of different Add-Ins for Visual Studio see Visual Studio Gallery . Please share your experiences and favorites. As motivation, here are some of my favorites: Versioning Controlled ...
75 votes
7 answers
56k views

Why aren't static const floats allowed? [duplicate]

I have a class which is essentially just holds a bunch of constant definitions used through my application. For some reason though, longs compile but floats do not: class MY_CONSTS { public : ...
Jon Cage's user avatar
  • 37k
73 votes
4 answers
149k views

error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj

I was converting my projects from VS2010 to VS2012.But I am getting an _MSC_VER linker error in certain projects. After a long surfing through google I found out that the issue is due to linking of a ...
mystack's user avatar
  • 5,198
73 votes
3 answers
50k views

placement new and delete

What is the right method to delete all the memory allocated here? const char* charString = "Hello, World"; void *mem = ::operator new(sizeof(Buffer) + strlen(charString) + 1); Buffer* buf = new(...
Vink's user avatar
  • 1,039
73 votes
6 answers
22k views

What's up with the thousands of warnings in standard headers in MSVC -Wall?

Some people seem to advise you use -Wall, but when I did it on a small test project which just has a main.cpp with some includes, I get 5800 warnings most of them in standard headers or in windows ...
user avatar
71 votes
12 answers
72k views

PCH Warning: header stop cannot be in a macro or #if block - Visual C++ 2010 Express SP1

This is pasted from a website, which presumably was working. I did some googling and found that the issue I have now is a result of Visual C++ 2010 SP1, which I downloaded today, and is now giving me ...
pighead10's user avatar
  • 4,215
70 votes
4 answers
36k views

Have a static lib, is there a simple way to know it is for 32 bit or 64 bit?

Is there any tool that can directly test if a library is made for 32 or 64 bit?
user705414's user avatar
  • 20.9k
69 votes
18 answers
58k views

How to create a UTF-8 string literal in Visual C++ 2008

In VC++ 2003, I could just save the source file as UTF-8 and all strings were used as is. In other words, the following code would print the strings as is to the console. If the source file was saved ...
brofield's user avatar
  • 2,236
69 votes
8 answers
40k views

Finding "dead code" in a large C++ legacy application [closed]

I'm currently working on a large and old C++ application that has had many developers before me. There is a lot of "dead code" in the project, classes and functions that aren't used by anyone anymore. ...
gudnithor's user avatar
  • 840
67 votes
7 answers
148k views

Unexpected end of file error

I hope you can help me, cause I have no idea about what's going on. I'm having the following error while trying to add Beecrypt library to my project: fatal error C1010: unexpected end of file ...
Andrey Chernukha's user avatar

1
2 3 4 5
337