All Questions
Tagged with c++ visual-c++
16,839
questions
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 ...
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")
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:
...
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): ...
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
////////////////////////////////////////////...
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 ...
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::...
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 = ...
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.
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.
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?
...
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 ...
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 ...
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 ...
114
votes
6
answers
87k
views
C++ #include and #import difference
What is the difference between #include and #import in C++?
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 ...
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 ...
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 ...
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....
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 ...
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 ...
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 ...
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 ...
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).
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 ...
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?
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.
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 ...
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?
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 ...
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 ...
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 ...
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#?
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 ...
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 ...
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 ...
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,...
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?
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 ...
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 :
...
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 ...
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(...
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 ...
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 ...
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?
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 ...
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. ...
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 ...