visual-c++

Visual C++ 10 lowercases the __FILE__ macro

。_饼干妹妹 提交于 2020-01-11 08:53:26
问题 The __FILE__ preprocessor macro in Visual C++ 10 expands to the name of the source module, but in lowercase, e.g. c:\path\to\my\file\somesource.cpp when the file name is actually SomeSource.cpp Is it possible to change this behaviour? 回答1: As suggested by Hans Passant, I asked the question on Microsoft Connect and got the following answer: Thanks for noting this. This behavior has existed for a while, at least back to VS 2008. Changing the default behavior could potentially be a breaking

function-try-block and noexcept

假装没事ソ 提交于 2020-01-11 08:25:08
问题 For the following code struct X { int x; X() noexcept try : x(0) { } catch(...) { } }; Visual studio 14 CTP issues the warning warning C4297: 'X::X': function assumed not to throw an exception but does note: __declspec(nothrow), throw(), noexcept(true), or noexcept was specified on the function Is this a misuse of noexcept ? Or is it a bug in Microsoft compiler? 回答1: Or is it a bug in Microsoft compiler? Not quite. A so-called function-try-block like this cannot prevent that an exception will

Read complex numbers (a+bi) from text file in C++

≡放荡痞女 提交于 2020-01-11 06:57:11
问题 i want to read an array of complex numbers (in a+bi form). There are several suggestions I found on the internet, however those methods only result the real part , while the imaginary part is always 0 . And infact the real part of the next number is the imaginary of the previous number. For example, I have an text file as follow: 2+4i 1+5i 7+6i And here is a suggestion for reading complex data int nRow = 3; std::complex<int> c; std::ifstream fin("test.txt"); std::string line; std::vector<std:

Can you make a VC++ Solution set preprocessor #defines on loaded projects?

主宰稳场 提交于 2020-01-11 05:31:05
问题 I have a library which supports a #define to control how it's built. However the library can be used by multiple EXE projects which want different versions. Can I make the app/EXE project set the #define to be used by the library when built, or set it in the solution? The only other option I can think of is creating a separate build-configuration on the library project but that would quickly get out of control. That's common for e.g unicode/non-unicode builds but then you'd end up multiplying

Converting _TCHAR* to char*

一曲冷凌霜 提交于 2020-01-11 05:30:10
问题 I'm trying to get a simple OpenCV sample working in C++ on Windows and my C++ is more than rusty. The sample is fairly simple: #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main( int argc, char** argv ) { if( argc != 2) { cout <<" Usage: display_image ImageToLoadAndDisplay" << endl; return -1; } Mat image; image = imread(argv[1], IMREAD_COLOR); // Read the file if(! image.data ) // Check for invalid

Visual C++ Volatile

杀马特。学长 韩版系。学妹 提交于 2020-01-11 04:52:10
问题 The MSDN docs for "volatile" in Visual C++ indicate that writes have "release semantics" and that reads have "acquire semantics", in addition to ensuring that reads always read from memory and that writes always write accordingly. The C spec for "volatile" includes the second part (don't do crazy optimizations), but not the first part (a memory fence). Is there any way in Visual C++ to get the "C" volatile behaviour only, without the memory fence? I want to force a variable to always be on

Why are doubles added incorrectly in a specific Visual Studio 2008 project?

让人想犯罪 __ 提交于 2020-01-10 19:55:28
问题 Trying to port java code to C++ I've stumbled over some weird behaviour. I can't get double addition to work (even though compiler option /fp:strict which means "correct" floating point math is set in Visual Studio 2008). double a = 0.4; /* a: 0.40000000000000002, correct */ double b = 0.0 + 0.4; /* b: 0.40000000596046448, incorrect (0 + 0.4 is the same). It's not even close to correct. */ double c = 0; float f = 0.4f; c += f; /* c: 0.40000000596046448 too */ In a different test project I set

Redefinition and Enumerator

牧云@^-^@ 提交于 2020-01-10 14:12:44
问题 I'm having a problem with enumerators. Let's not waste anyone's time, and get straight to it. The error: 1> forgelib\include\forge\socket.h(79): error C2365: 'RAW' : redefinition; previous definition was 'enumerator' 1> forgelib\include\forge\socket.h(66) : see declaration of 'RAW' The code: namespace Forge { enum SocketType { STREAM = SOCK_STREAM, // Sequenced, reliable, 2-way DGRAM = SOCK_DGRAM, // Connectionless, unreliable RAW = SOCK_RAW, // Raw protocol RDM = SOCK_RDM, // Reliable

Redefinition and Enumerator

六月ゝ 毕业季﹏ 提交于 2020-01-10 14:12:40
问题 I'm having a problem with enumerators. Let's not waste anyone's time, and get straight to it. The error: 1> forgelib\include\forge\socket.h(79): error C2365: 'RAW' : redefinition; previous definition was 'enumerator' 1> forgelib\include\forge\socket.h(66) : see declaration of 'RAW' The code: namespace Forge { enum SocketType { STREAM = SOCK_STREAM, // Sequenced, reliable, 2-way DGRAM = SOCK_DGRAM, // Connectionless, unreliable RAW = SOCK_RAW, // Raw protocol RDM = SOCK_RDM, // Reliable

Redefinition and Enumerator

故事扮演 提交于 2020-01-10 14:12:01
问题 I'm having a problem with enumerators. Let's not waste anyone's time, and get straight to it. The error: 1> forgelib\include\forge\socket.h(79): error C2365: 'RAW' : redefinition; previous definition was 'enumerator' 1> forgelib\include\forge\socket.h(66) : see declaration of 'RAW' The code: namespace Forge { enum SocketType { STREAM = SOCK_STREAM, // Sequenced, reliable, 2-way DGRAM = SOCK_DGRAM, // Connectionless, unreliable RAW = SOCK_RAW, // Raw protocol RDM = SOCK_RDM, // Reliable