views:

43

answers:

1

I'm trying to write a program in python to run a program in C++. It wasn't working right, so I made the most basic version of each I could. The C++ program merely takes in a string from stdin, and then prints it out. The Python code is written as follows:

import popen2, string, StringIO

fin, fout = popen2.popen2("PyTest")
msg = ur"Hello, world!"
print msg
fout.write(msg)
print fin.readline()

The output, however looks like this:

Hello, world!
Hello,

The problem I keep seeing is that spaces seem to break apart the string, even though it is a string literal. I'm not really sure what to do here. Any suggestions?

+2  A: 

In C++, std::cin >> mystring uses spaces as separators. Use std::getline instead if you want to gobble up a whole line at a time.

Alex Martelli