I’ve been trying to learn how to extend Python 3 with C++, and I was recommended using Boost. I believe I’ve followed the procedure of setting up Boost::Python correctly so far, and I have the following code from here (saved as example.cpp) which builds successfully:
#include <boost/regex.hpp>
#include <iostream>
#include <string>
int main()
{
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
}
The instructions suggested testing this worked by creating a text file called jayne.txt and saving data inside it, and then executing the program from a command prompt and passing in the path to the file as an argument. I don’t know C++ very well at all and I’ve been having difficulties with this.
I’ve tried opening the command prompt, and running “path/to/example.cpp” < “path/to/jayne.txt” and “path/to/example.cpp” “path/to/jayne.txt”, both from a regular command prompt and from Visual Studio Command Prompt. I should be getting output somewhere, but all that happens is that it opens the program in Visual Studio if it’s not already open.
I’m working with MVSC++ 2010 in Windows 7.
C++ is a compiled language – thus, in order to run a program, you need to run the compiled version (
.exe) rather than the source code (.cpp).When you type
"path/to/example.cpp"at the command line, it’s opening the source code. Find the actual executable from building your code (generally it’s located in abuildorDebugfolder for MSVC) and run that on the command line and the<operator should work fine.