Recently i installed visual studio community edition and tried to write small console application.
Program is getting build successfully. But console window is not getting pop up.
Is there a problem, i installed the visual studio on my System "D" drive.
My code snippet :
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Hello world";
return 0;
}
Kindly help
Add a cin.get() like so:
int main() {
cout << "Hello world";
cin.get(); // <- Waits for any key press directed at the console window
return 0;
}
Related
My code :
main.cpp
#include <iostream>
namespace file {
#include "file.cpp"
}
namespace file2 {
#include "file1.cpp"
}
int main() {
file::hello();
return 0;
}
file.cpp
#include <iostream>
void hello() {
std::cout << "hello";
}
file1.cpp
#include <iostream>
void hello() {
std::cout << "hello world";
}
My problem:
I use virtual studio, and i don't know why this does not work.I try it allready on CodeBlock and it was fine. But in VS i have error with at least one repeatedly defined symbol has been found.
Sorry for my english.
Since VS still builds and links file.cpp and file1.cpp to the executable you get the errors. You can exclude them from the project by changing its properties or make them regular header files and include them as such.
The include will literally just copy the content of the file into the name space declaration of main.cpp.
I tried to use C++ amp in Visual Studio 2017, but compiler said, "error C3564" and I tried the old code(which worked in Visual Studio 2015), and it said same thing.
Does Visual Studio 2017 support C++ amp?
#include "stdafx.h"
using namespace concurrency;
int main(void){
int size;
scanf_s("%d", &size);
array_view<int, 1> a(1);
parallel_for_each(extent<1>(1),
[=](index<1> &idx) restrict(amp)
{
a(idx) = size;
});
}
the code above will generate problem.
just added the amp.h file and the code above compiles.
i am also working on other project with C++AMP in vs 2017 and it working fine.
#include "stdafx.h"
#include <amp.h>
using namespace concurrency;
int main(void) {
int size;
scanf_s("%d", &size);
array_view<int, 1> a(1);
parallel_for_each(extent<1>(1),
[=](index<1> &idx) restrict(amp)
{
a(idx) = size;
});
}
I'm trying to write a simple application that will enumerate all the ProductCodes installed on my machine.
I've started a new project in Visual Studio 2013, but whenever I build I get the error:
"LNK2019: unresolved external symbol _MsiEnumProductsExA#32 referenced in function _main"
I've been trying to figure out how to add msi.lib to my project include path, but I can't seem to figure it out.
Here's my code:
#define _WIN32_MSI 300
#include <Windows.h>
#include <iostream>
#include <string>
#include <Msi.h>
using namespace std;
int main() {
// Get a list of all installed MSIs
DWORD index = 0;
TCHAR currentProductCode[40] = {0};
unsigned int result = ERROR_SUCCESS;
// Open an MSI handle
while (ERROR_SUCCESS == result) {
result = MsiEnumProductsEx(NULL, "s-1-1-0",
MSIINSTALLCONTEXT_USERMANAGED | MSIINSTALLCONTEXT_USERUNMANAGED | MSIINSTALLCONTEXT_MACHINE,
index, currentProductCode, NULL, NULL, NULL);
if (result == ERROR_SUCCESS) {
cout << "current ProductCode: " << currentProductCode;
}
index++;
}
return 0;
}
I've been trying to update the project's Property Pages by adding the path to the msi.lib to the "Library Directories" property, but that doesn't seem to work:
This is like Visual Studio 101, what am I missing?!
Goto Configuration Properties>Linker>Input
Add msi.lib in Additional Dependencies Thats it! Make sure you are using same calling conversion, which used to built the lib. i.e either stdcall or cdecl.
I'm trying to run the below c++ code in Visual Studio compiling with both Visual C++ and İntel Compiler. I'm setting the /Qopenmp option. Although the omp_get_max_threads() result is 2 the "printf("Running on multiple threads\n")" part is not printed twice.
This is the code:
#include <omp.h>
int main(int argc, char* argv[])
{
printf("Starting Program!\n");
int ntr;
omp_set_dynamic(0);
omp_set_num_threads(2);
#pragma omp parallel
{
printf("Running on multiple threads\n");
ntr = omp_get_max_threads();
printf("%d\n",ntr);
}
printf("Finished!\n");
return 0;
}
This is the output
Starting Program!
Running on multiple threads
2
Finished!
What is wrong with this code or Visual Studio settings?
I am trying now to execute a C++ program in eclipse, but it doesn't show anything, my code is:
#include<iostream.h>
using namespace std;
int main()
{
cout<<"i have stucked here, plz do some thing for Me !";
return 0;
}
I think I am not ok in setting variable path. It is
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\QuickTime\QTSystem\;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Samsung\Samsung PC Studio 3\;C:\soft\cygwin\bin
while my bin path is
c:\cygwin\bin
Try this:
#include<iostream>
using namespace std;
int main()
{
cout<<"I am stuck here, please do some thing for Me !";
return 1;
}
remove ".h" from header iostream.h because now .h forms are deprecated from c++ library., this is working fine for me..
#include<iostream>
using namespace std;
int main()
{
cout<<"I am stuck here, please do some thing for Me !";
return 0;
}