I thanks for all your comments. I tested on Mac OS X and compiles flawlessly under gcc and Clang compilers. Still puzzles why not getting my Windows 10 VS2017 to compile. I have tested setting the options for pointing specific to the BuildTool compiler but still getting an error. It looks like a problem with WM detecting the libraries. but I am not an authority and not able to be sure if the problem is with the VS installation itself.
Needs["CCompilerDriver`"]
CCompilers[]
hello = CreateExecutable["
// Hello100.cpp : Defines the entry point for the console \
application.
//#include \"stdafx.h\"
#include <iostream>
// i/o example
// stringstreams
#include <string>
#include <sstream>
using namespace std;
int main()
{
string mystr;
float price = 0;
int quantity = 0;
int next;
cout << \" Enter price : \";
//getline(cin, mystr);
//stringstream(mystr) >> price;
cout << \" Enter quantity : \";
//getline(cin, mystr);
//stringstream(mystr) >> quantity;
cout << \" Total price : \" << price * quantity << endl;
//cin >> next;
return 0;
}
", "hellomyfirst", Language -> "C++",
"Name" -> "Visual Studio",
"Compiler" ->
CCompilerDriver`VisualStudioCompiler`VisualStudioCompiler,
"CompilerInstallation" ->
"C:\\Program Files (x86)\\Microsoft Visual \
Studio\\2017\\BuildTools", "CompilerName" -> Automatic
]
Import["!" <> QuoteFile[hello], "Text"]
Here is the output:
Out[11]= {{"Name" -> "Visual Studio", "Compiler" ->
CCompilerDriverVisualStudioCompiler
VisualStudioCompiler,
"CompilerInstallation" -> "C:\Program Files (x86)\Microsoft
Visual \ Studio\2017\Community", "CompilerName" -> Automatic},
{"Name" -> "Visual Studio", "Compiler" ->
CCompilerDriverVisualStudioCompiler
VisualStudioCompiler,
"CompilerInstallation" -> "C:\Program Files (x86)\Microsoft
Visual \ Studio\2017\BuildTools", "CompilerName" -> Automatic}}
Out[2]= {{"Name" -> "Visual Studio", "Compiler" ->
CCompilerDriverVisualStudioCompiler
VisualStudioCompiler,
"CompilerInstallation" -> "C:\Program Files (x86)\Microsoft
Visual \ Studio\2017\Community", "CompilerName" -> Automatic},
{"Name" -> "Visual Studio", "Compiler" ->
CCompilerDriverVisualStudioCompiler
VisualStudioCompiler,
"CompilerInstallation" -> "C:\Program Files (x86)\Microsoft
Visual \ Studio\2017\BuildTools", "CompilerName" -> Automatic}}
During evaluation of In[1]:= CreateExecutable::cmperr: Compile error:
C:\Program Files (x86)\Microsoft Visual
Studio\2017\BuildTools\VC\Tools\MSVC\14.13.26128\include\crtdefs.h(10):
fatal error C1083: Cannot open include file: 'corecrt.h': No such file
or directory
Out[3]= $Failed
During evaluation of In[1]:= StringJoin::string: String expected at
position 2 in !<>QuoteFile[$Failed].
During evaluation of In[1]:= Import::chtype: First argument
!<>QuoteFile[$Failed] is not a valid file, directory, or URL
specification.
Out[4]= $Failed