visual studio - invalid std::string debugger output in Release mode - c++

There's nothing fancy going on in this program, but I get garbage output. Here are the header files I'm including, in case that's relevant.
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <vector>
#include <string>
#include <sstream>
And I'm using Visual Studio 2008 on Windows XP.
Note that if I print the string to stdout, it prints "test" perfectly fine.

Sometimes the debugger will have trouble picking up proper values if you've compiled in Release mode. The compiler might swap around operations or move values to registers, etc.

Related

Errors when including intrin.h?

I'm trying to build my project, which uses things like __cpuid and __cpuidex, so I need intrin.h. When I try to include it and build my project, I get two errors. They are:
`tagMENUBARINFO::fUnused`: type of bit field too small for number of bits
in winuser.h, and in minwindef.h I get the error
`BOOL`: redefinition; different basic types
My includes:
#include <Windows.h>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <algorithm>
#include <intrin.h>
I need all of these includes, so removing some isn't really an option.
I'm using Visual Studio 2019 as my compiler, my Windows SDK Version is 10.0, and the C++ language standard is ISO C++14 Standard.

Where is '__find_end' present in Visual Studio 19 C/C++ Development Tools?

I was trying to compile an old code, and received the following error:
error G1A4676F8: no member named '__find_end' in namespace 'std'
I searched online and found it is defined in stl_algo.h, which I couldn't find in my Windows system. Also, the documentations were of libstdc++4 and earlier.
The code compiles fine on https://godbolt.org/ with all MSVC versions.
The include statements are:
#include <string>
#include <algorithm>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <stdexcept>
The compiler shows an alternative as find_end defined in algorithm but I am not sure if __find_end has the same functionality as find_end.
So, my question is, is __find_end deprecated?
If not, where can I find it's declaration in Windows?
If yes, what are my alternatives? Is find_end a perfect substitute for __find_end?

Why does changing the order of including psapi.h gives compilation erros?(Indentifier BOOL is undefined)

I am using Visual Studio Community 2017 to code c++. When I run the following code everything works fine.
#include "pch.h"
#include<Windows.h>
#include<Psapi.h>
#include <iostream>
#include <conio.h>
int main()
{
std::cout << "Really!! How do you do it?";
_getch();
}
But if I change the order of #includes by including psapi.h before Windows.h, compiler goes badass and throws 198 errors at me, which surprisingly(maybe only to me) includes Identifier "BOOL" is undefined.
Why is this happening?
Since Psapi.h's include tree is trivial, I'm going to exemplify. Everything relies on VStudio 2015 (Community) (v14.0.25431.01 Update 3) and Windows Kits 8.1 (? funny, because v10 is there too) files (with default env vars and preprocessor definitions):
BOOL is defined in minwindef.h (#157: typedef int BOOL;)
Psapi.h only includes one file (#27: #include <winapifamily.h>)
winapifamily.h doesn't include any other file
So, when reaching Psapi.h (#87: BOOL WINAPI EnumProcesses (...), the compiler doesn't know anything about BOOL, so it complains.
Windows.h includes minwindef.h (indirectly, via windef.h), and that's why it works when you include it before Psapi.h.
Personally, I think it's a bug in Psapi.h, since it's not self contained, but there might be a good reason (that I'm not aware of) for that. Anyway, if this is indeed a bug, it wouldn't be MS's 1st one :)
#include <Windows.h>
#include <WinSock2.h>
// main present just for rigorosity's sake
int main() {
return 0;
}
to answer the question, I know this is DATED but the issues persist today. You need the following:
#include "stdafx.h"
#include <stdbool.h>
#include <Windows.h>
#include <stdlib.h>
#include <psapi.h>
After stdlib.h was included, the errors were gone.

Where is strtof() in VS2012?

I can litterally not find which library/header this function is in, I've looked at so many examples of people using this function, but there are no results...
These are all the stuff I've included:
#include "Console.h"
#include "Direct3D9.h"
#include <string>
#include <cerrno>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
But still strtof comes up as "Error namespace "std" has no member "strtof""
What I'm trying to do:
flValue = std::strtof( vszArgs.at( 1 ).c_str( ), NULL );
pConVar->Set( flValue );
Visual Studio 2012 does not implement strtof.
Link to MSDN bug report which includes a suggested workaround.
You can find it in cstdlib when using C++11. The information can easily be found here : http://www.cplusplus.com/reference/cstdlib/strtof/?kw=strtof
My guess is that you aren't compiling using c++11.
1) Include stdlib.h
#include <stdlib.h> /* strtof */
from http://www.cplusplus.com/reference/cstdlib/strtof/
If that still doesn't work...
2) Make sure your compiler is C++11 or newer
It's new as of C++11 so if you have an older compiler it won't work.
If that still doesn't work...
3) Your compiler may just not support it
Visual C++ 2012 does not have full support for the C++11 standard. See the Visual Studio bug "Missing strtof, strtold, strtoll, strtoull functions from stdlib.h".
We don't yet have those functions in the CRT. We will consider adding them to a future version of Visual C++.

C++ #include not working in Microsoft Visual Studio 2010

I have been using Visual Studio and I think I must have messed with some setting. I can't include basic things like <iostream>. How can I fix this?
#include <iostream> // for standard I/O
#include <string> // for strings
#include <iomanip> // for controlling float print precision
#include <sstream> // string to number conversion
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
using namespace std;
using namespace cv;
All the above lines are in red squiggle below. My guess is while trying to configure Visual Studio to use OpenCv, I messed with some setting.
More than likely, you forgot to add 'using namespace std' as pretty much nothing in iostream is really useful without it. If you are getting 'cant find ...', then you have a setup problem and should reinstall Visual Studio because the headers were not properly placed.
Hope this helps, feel free to post your code and I can tell you for sure what the problem is, but that is the most likely of them.