开发者

Python and C++ integration. Python prints string as multiple lines

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 prin开发者_Python百科ts 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜