我是一名 Python 新手,在将 Python 3.2 嵌入 C++ 代码中时遇到问题。
这是一个例子。代码如下所示:
std::cout << "Hello world" << std::endl;
std::wcout << "Hello world" << std::endl;
PyIntitialize();
std::cout << "Hello world" << std::endl;
std::wcout << "Hello world" << std::endl;
控制台输出如下所示:
Hello World
Hello World
Hello World
H e l l o W o r l d
看来 wchar_t 的宽度已被 Python 重置为其原始大小的两倍。另一方面,初始化后字符的宽度保持不变。
细节:
Win7 - 64 位。
用于上面 C++ 代码示例的 Visual Studio 2008。
我还使用 Visual Studio 2008 从源代码构建 Python。
为什么 Python 会改变 stdoutput 流(如果确实如此)以及我能做些什么来解决这个问题?我们在整个代码中使用 wcout,因此它必须能够工作(事实上,当我们使用 Python 2.6 时它确实有效)。
非常感谢。
I'm a Python newbie having problems with embedding Python 3.2 in a piece of C++ code.
Here's an example. The code looks like this:
std::cout << "Hello world" << std::endl;
std::wcout << "Hello world" << std::endl;
PyIntitialize();
std::cout << "Hello world" << std::endl;
std::wcout << "Hello world" << std::endl;
And the console output looks like this:
Hello World
Hello World
Hello World
H e l l o W o r l d
It appears that the width of a wchar_t has been reset by Python to twice its original size. On the other hand the width of a char remains the same after the initialization.
Details:
Win7 - 64 bit.
Visual Studio 2008 for the C++ code sample above.
I'm also using Visual Studio 2008 to build Python from source.
Why is Python changing the stdoutput stream (if this is indeed the case as it appears) and what can I do to fix the problem? We use wcout throughout the code, so it has to work (and indeed it did when we were using Python 2.6).
Many thanks.
发布评论