displaying the output in Ouput windows in visual studio 2015 - c++

I'm debugging the c++ console application in visual studio 2015 but output is not displaying in debug output window.
std::ostringstream buffer;
std::cout << "\n result: \n";
for (int i = 0; i < size; i++)
{
buffer << array[i] << ",";
}
buffer << "\n";
In the output there are some warnings Cannot find or open the PDB file but it may not be reason.
What is the problem ?

To display in MSVC debug output you need to use ::OutputDebugString().
eg ::OutputDebugString( buffer.str() );

Related

In Visual Studio 2019 can't read text file from release mode but works fine in debug (running within VS)

I am currently trying to read in a text file for use in a project but when running in release form (running the .exe file from a command window) the file doesn't read in. But yet in debug mode it works fine. I have tried having the files in the same directory as the .exe file but it doesn't seem to find it and I don't know why?
The code:
std::cout << "Acquiring data file..." << endl;
std::cout << "Reading data file..." << endl;
ifstream tempData;
tempData.open("temp_lincolnshire_short.txt");
if (tempData.is_open()) {
std::cout << tempData.rdbuf() << endl;
}
else {
cout << "Reading failed..." << endl;
}
tempData.close();
std::cout << "Data file closed." << endl;
What I ended up using was a relative path as identified on https://stackoverflow.com/a/35910234/3795116 which ended up being:
myFile.open("../Release/frequency.dat", ios::in);
*changing myFile to whatever your variable is.

After compiling C++. a.exe in visual studio is not showing output but when I am running simple program it gives output

enter image description here
1.After executing a.exe is not showing output in visual studio terminal and also in powershell admin mode.It is also not giving any error.
but when running hello world program it gives output.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> g1;
for (int i = 1; i <= 5; i++)
g1.push_back(i);
cout << "Output of begin and end: ";
for (auto i = g1.begin(); i != g1.end(); ++i)
cout << *i << " ";
return 0;
}
Your code is showing but it just exits out so fast you can't tell what it returned. Advise checking this out: How to stop C++ console application from exiting immediately?
Have you set the program to the console program? Property -> Linker -> System -> Subsystem -> "Console(/SUBSYSTEM:CONSOLE)"

Command Arguments field in Visual Studio 2015

I try to pass some arguments to the program using Visual Studio Community 2015.
I add some input in the Configuration Properties - Debugging - Command Arguments.
#include <iostream>
int main(int args, char* argv[])
{
std::cout << "args:" << args << std::endl;
for (size_t i = 0; i < args; i++)
{
std::cout << "argv[" << i << "]=" << argv[i] << std::endl;
}
}
The output is:
args:1
argv[0]=c:\users\john\documents\visual studio 2015\Projects\ConsoleApplication2\Debug\ConsoleApplication2.exe
Why the input in the "Command Arguments" field is ignored?
Are you sure the build configuration you set the command line for is the one you are running? VS allows different command line arguments to be set for each build (debug/release and platforms by default).

Open a dll (get handle) in c++

I'm looking to load a dll library in c++, visual studio.
When I do I get error code 193, this is:
ERROR_BAD_EXE_FORMAT
193 (0xC1)
%1 is not a valid Win32 application.
The code is below
using namespace std;
int main(){
HINSTANCE dllhandle =
LoadLibrary(L"C:\\LKG5000_DLL_ver1_10\\English\\64bit\\LKIF2.dll");
cout << dllhandle << endl;
if (dllhandle != 0)
{
cout << "Created Handle" << endl;
}
else
{
cout << ":(" << endl;
}
cout << GetLastError() << endl;
getchar(); //Lazy way to keep cmd window open
return 0;
}
Any suggestions? Thanks
Given the DLL path it looks like it's a 64-bit (WIN64) DLL.
Make sure your program that is trying to load that DLL is compiled for 64-bit target as well.
You can't load a 64-bit DLL in a 32-bit application or the other way around.
Read here for more details.

QSerialPortInfo debug crash visual studio 2015 + QT5.8

I am using QT5.8 and visual studio 2015 on win10 to control a serial port.
The following minimal code crashes in visual studio (but only in debug, release works fine) after the visualization of the messages, so when the object QList infos is destroyed, can anybody explain why?
#include <iostream>
#include <QtSerialPort/QSerialPortInfo>
void showPorts() {
QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : infos) {
std::cout << " detected port : " << info.portName().toStdString() << std::endl;
}
} // this code CRASHES HERE only in debug !
int main (int argc, char** argv){
std::cout<<"\n >>> test serial info <<< \n\n"<<std::endl;
showPorts();
std::cout << "\n >>> Finished, press enter to exit <<< \n\n" << std::endl;
std::cin.get();
return 0;
}
I have tested your code and I have not a crash.
PS: Windows 10x64, MSVC2015, Qt 5.8.0 32 bit