On 4/23/2015 6:24 PM, Stefan Ram wrote:
> Is this a C++ that should be able to be compiled
> without compilation errors by a C++ compiler?
No. But see below.
> #include <initializer_list>
> #include <iostream>
> #include <ostream>
> #include <string>
> #include <regex>
> #include <thread>
> #include <memory>
>
> void alpha() { ::std::cout << "alpha\n"; }
>
> int main()
> { ::std::unique_ptr< ::std::string >s =
> ::std::make_unique< ::std::string >( "string" );
> ::std::regex pat {R"(\w{2}\s*\d{5}(-\d{4})?)"};
> ::std::cout <<( "example"s ).find( 'x' ) << '\n';
> ::std::thread t( alpha ); t.join(); }
Has errors. (see below)
> Do you know a C++-Implementation for Windows that can
> execute this program (possibly after typos were corrected)?
> I am looking for a »precompiled binary« or windows
> installer, not a source tree.
Get Cygwin. It's a free development platform for Windows
which gives Windows a Linux-like feel (replaces cmd with
Bash for one thing, and re-interprets your file system
so that the Cygwin folder is / and the rest of your C: drive
is /cygdrive/c ). It has available compilers and interpreters
for a wide variety of programming languages: C, C++, Perl,
Python, Ruby, Haskel, and many more.
But your program has problems, even after I cleaned up some
of the more obvious errors (such as loads and loads of
superfluous colons):
#include <initializer_list>
#include <iostream>
#include <ostream>
#include <string>
#include <regex>
#include <thread>
#include <memory>
void alpha(void) {
std::cout << "alpha" << std::endl;
}
int main(void)
{
std::unique_ptr<std::string> s =
std::make_unique<std::string> ("string");
std::regex pat {R"(\w{2}\s*\d{5}(-\d{4})?)"};
std::cout << ("examples").find('x') << std::endl;
std::thread t(alpha);
t.join();
return 0;
}
Compilation attempt with g++ gives these errors:
%g++ -Wall -std=c++11 program.cpp -o program.exe
weird-program.cpp: In function ‘int main()’:
weird-program.cpp:16:7: error: ‘make_unique’ is not a member of ‘std’
std::make_unique<std::string> ("string");
^
weird-program.cpp:16:35: error: expected primary-expression before
‘>’ token
std::make_unique<std::string> ("string");
^
weird-program.cpp:18:30: error: request for member ‘find’ in
‘("examples")’, which is of non-class type ‘const char [9]’
std::cout << ("examples").find('x') << std::endl;
^
Hmmm. Function "make_unique" *should* be in header <memory>.
Ah, I see, I'm compiling with std=c++11, but I need std=c++14.
Then you need to rethink your usage of "find" a if it were
a method of a string literal. String literals don't have
methods. But std::string does, so i'll make that correction
for you. Yes, THIS version compiles:
#include <initializer_list>
#include <iostream>
#include <ostream>
#include <string>
#include <regex>
#include <thread>
#include <memory>
void alpha() {
std::cout << "alpha\n";
}
int main(void)
{
std::unique_ptr<std::string> s =
std::make_unique<std::string>("string");
std::regex pat {R"(\w{2}\s*\d{5}(-\d{4})?)"};
std::cout << std::string("examples").find('x') << std::endl;
std::thread t(alpha);
t.join();
return 0;
}
%g++ -Wall -std=c++14 program.cpp -o program.exe
[no errors, no warnings]
On running, prints:
1
alpha
--
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley