如何将布尔数组或 Unsigned Char* 传递给 cout?
我将 76800 个布尔值的数组(可以是整数或 unsigned char* 代替)传递给 Actionscript (AIR)。到目前为止,我想出的最佳解决方案是将我的 C++ 应用程序作为 NativeProcess 启动,这使我的 AIR 应用程序能够访问标准输出。
我的解决方案有点工作,但我觉得这是一个可怕的黑客,而且我对 ostream 的理解不够好,不知道如何传递东西:
// Variables
stringstream ss;
int arrayLength = 76800;
// Put data into stringstream
for (int i = 0; i < arrayLength; ++i){
ss << data[i];
}
// Convert stringstream to stream
string message;
ss >> message;
// Send Data
cout << message;
是否有一种方法可以在一个大块中输出这些值而不将它们转换为字符串?
编辑:在 AS3 中,我理想地将传入的数据转换为 ByteArray 这样我就可以将它用作 BitmapData。
性能是问题所在 - 这本质上是我试图传递给 as3 的 2 位图像,因此这一切都需要每秒发生 15-30 次。
I'm passing an array of 76800 Booleans (could be integers or unsigned char* instead) to Actionscript (AIR). The best solution I've come up with so far is to launch my C++ app as a NativeProcess, which gives my AIR app access to stdout.
My solution is sort of working, but I feel it's a terrible hack, and I don't understand ostream well enough to know how else to pass things:
// Variables
stringstream ss;
int arrayLength = 76800;
// Put data into stringstream
for (int i = 0; i < arrayLength; ++i){
ss << data[i];
}
// Convert stringstream to stream
string message;
ss >> message;
// Send Data
cout << message;
Is there a way to output these values in one big block without turning them into a string?
Edit: in AS3, I'd ideally cast this incoming data as a ByteArray so that I can use it as BitmapData.
Performance is the issue, here - this is essentially a 2-bit image I'm trying to pass to as3, so this all needs to happen 15-30 times per second.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为第一遍,为什么要费心将它们放入流中,只是将其转换为字符串并将其写入流呢?只需一次性完成即可:
As a first pass, why bother putting them into a stream only to convert that to a string and write that to a stream? Just do it in one pass:
使用
boolalpha
标志,如下所示:Use the
boolalpha
flag, like this: