Can't get an output from my c++ application - c++

I'm using Microsoft Visual C++ Express, and I'm wondering what's wrong with the following application, I can't get an output, it gives me an error. Since I'm not English, the error is in a different language, but it basically says something along the lines of 'The system can't find the given/stated path'.
I have literally checked it a dozen times but I can't seem to find what I'm doing wrong. Here's the code:
#include <iostream>
using namespace std;
int DemoConsoleOutput ()
{
cout << "This is a simple string literal" << endl;
cout << "Writing number five:" << 5 << endl;
cout << "Performing division 10/5 = " << 10 / 5 << endl;
cout << "Pi when approximated is 22 / 7 = " << 22 / 7 << endl;
cout << "Pi more accurately is 22 / 7 = " << 22.0 / 7 << endl;
return 0;
}
int main()
{
return DemoConsoleOutput ();
}
Can anyone help me find what's wrong with this?
Addendum: I also keep getting a weird error on my computer every couple minutes. It says: 'a program can't display a message on the desktop' and it gives me the options to show the message, or to give me another reminder in a few minutes. When I click 'show message' my screen goes black for a second and it then gives an error 'The application data folder for Microsoft visual c++ 2010 express could not be created'.
I don't know if it's important, but my OS is windows vista.

From the situation it seems that the application has insufficient rights to create a working folder and write an file in that folder. Possible causes can be that your anti virus is not letting VS do so or the folder has no write rights. Please go through this question.

Related

How to format output of a SQL query in C++?

Im working on a school assignment in which i need to format a query of some dummy data. The specific query gathers data on a few fields in a set of two tables, and prints it out to the console in C++.
While this works as expected, the only issue is formatting output so that it appears correctly. In our example output in the assignment document, this is shown as being the proper output
<ID> <name> <email> <phone> <ext> <manager>
not the exact spacing but more or less what needs to be done. The initial output i get in the console is similar to this, and looks like:
1056 Tim Tomphson ttomph#fakeEmailService.com +1 800 555 1580 x5122 Tom Timsphon
Until about a few entries down when suddenly the data becomes completely unformatted.
Now im confused, cause I thought i had the formatting right, and dont know why its fallen to hell around that point specifically since everything else up to that was basically perfect. and i dont know how to format it right so that it can return to a proper tabular output.
the code im using for this output is
cout << left << setw(10) << temp.empNum << "\t" << temp.firstName << " " << temp.lastName << "\t\t" << temp.email << "\t\t" << temp.phone << "\t\t" << temp.extension << "\t\t" << temp.reportsTo << endl;
I've also tried using printf statements, but that had less luck and was nowhere as close to successful as this command itself...does anyone have any ideas that could help me out?

Special Characters Not Working in Windows 10 [duplicate]

I'm working on a poker game in c++ using Visual Studio Express 2013 on Windows 10. When i use the following code to assign suits to my cards the console displays all question marks in the place of the suits.
void printHand(Card hand[])
{
const string SUIT = "\3\4\5\6";
const string RANK = "23456789TJQKA";
cout << "Your hand is: ";
for (int i = 0; i < SIZE; i++)
{
cout << RANK[hand[i].ranks] << SUIT[hand[i].suits] << " ";
}
cout << endl;
}
When I change the suits to other characters I get the right characters like question marks, colons... When I run a for loop to show all Ascii characters, the first 32 characters display as control characters like it doesn't recognize the font.
My question is whether this is because of Visual Studio 2013 Express, Windows 10, or my machine.
Check the checkbox in Properties that says "Use the old console" or something like that (Mine was in swedish). That solved the problem for me.
There are a number of things you must check:
Make sure your console is using Code Page 437
Failing that, make sure your program's locale is the default "C" locale.
Let us know if it still doesn't work.

google test framework best practice to fail a test from TestEventListener

I have TestEventListener that fails a test if it take more than some limit. I have the check in the OnTestEnd where I can check test_info.result()->elapsed_time() and I trigger the error with GTEST_FAIL.
void TimeMonitor::OnTestEnd(const ::testing::TestInfo& test_info)
{
...
GTEST_FAIL()
<< "This test took "
<< test_info.result()->elapsed_time() << " ms "
<< "instead the expected " << expected << " ms.";
}
This works with one very annoying exception - the error report code line points to the place where GTEST_FAIL() is. I know that this code is correct, I would like to be pointed out to the head of the test that failed instead.
How I can change the code to print the test head location?

ascii heart in c++ windows 10 not displaying

I'm working on a poker game in c++ using Visual Studio Express 2013 on Windows 10. When i use the following code to assign suits to my cards the console displays all question marks in the place of the suits.
void printHand(Card hand[])
{
const string SUIT = "\3\4\5\6";
const string RANK = "23456789TJQKA";
cout << "Your hand is: ";
for (int i = 0; i < SIZE; i++)
{
cout << RANK[hand[i].ranks] << SUIT[hand[i].suits] << " ";
}
cout << endl;
}
When I change the suits to other characters I get the right characters like question marks, colons... When I run a for loop to show all Ascii characters, the first 32 characters display as control characters like it doesn't recognize the font.
My question is whether this is because of Visual Studio 2013 Express, Windows 10, or my machine.
Check the checkbox in Properties that says "Use the old console" or something like that (Mine was in swedish). That solved the problem for me.
There are a number of things you must check:
Make sure your console is using Code Page 437
Failing that, make sure your program's locale is the default "C" locale.
Let us know if it still doesn't work.

Listing All Physical Drives (Windows)

How can I get all the physical drive paths (\\.\PhysicalDriveX) on a Windows computer, with C/C++?
The answers in this question suggest getting the logical drive letter, and then getting the physical drive corresponding to that mounted drive. The problem is, I want to get all
physical drives connected to the computer, including drives that are not mounted.
Other answers suggest incrementing a value from 0-15 and checking if a drive exists there (\\.\PhysicalDrive0, \\.\PhysicalDrive1, ...) or calling WMIC to list all the drives.[
As these seem like they would work, they seem like they are not the best approach to be taking. Is there not a simple function such as GetPhysicalDrives that simply returns a vector of std::string's containing the paths of all the physical drives?
You can use QueryDosDevice. Based on the description, you'd expect this to list things like C: and D:, but it will also lists things like PhysicalDrive0, PhysicalDrive1 and so on.
The major shortcoming is that it will also list a lot of other device names you probably don't care about, so (for example) on my machine, I get a list of almost 600 device names, of which only a fairly small percentage is related to what you care about.
Just in case you care, some (old) sample code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <iostream>
int main(int argc, char **argv) {
char physical[65536];
char logical[65536];
if ( argc > 1) {
for (int i=1; i<argc; i++) {
QueryDosDevice(argv[i],logical, sizeof(logical));
std::cout << argv[i] << " : \t" << logical << std::endl << std::endl;
}
return 0;
}
QueryDosDevice(NULL, physical, sizeof(physical));
std::cout << "devices: " << std::endl;
for (char *pos = physical; *pos; pos+=strlen(pos)+1) {
QueryDosDevice(pos, logical, sizeof(logical));
std::cout << pos << " : \t" << logical << std::endl << std::endl;
}
return 0;
}
However, if I run this like `devlist | grep "^Physical", it lists the physical drives.
Yes, you can just type NET USE. Here is an example output...
NET USE
New connections will be remembered.
Status Local Remote Network
-------------------------------------------------------------------------------
H: \\romaxtechnology.com\HomeDrive\Users\Henry.Tanner
Microsoft Windows Network
OK N: \\ukfs01.romaxtechnology.com\romaxfs
Microsoft Windows Network
OK X: \\ukfs03.romaxtechnology.com\exchange
Microsoft Windows Network
OK Z: \\ukfs07\Engineering Microsoft Windows Network
\\romaxtechnology.com\HomeDrive
Microsoft Windows Network
OK \\ukfs07\IPC$ Microsoft Windows Network
The command completed successfully.