如何将布尔数组或 Unsigned Char* 传递给 cout?

发布于 2024-12-21 08:58:04 字数 798 浏览 3 评论 0原文

我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小忆控 2024-12-28 08:58:04

作为第一遍,为什么要费心将它们放入流中,只是将其转换为字符串并将其写入流呢?只需一次性完成即可:

int arrayLength = 76800;

for (int i = 0; i < arrayLength; ++i) {
    cout << data[i];
}

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:

int arrayLength = 76800;

for (int i = 0; i < arrayLength; ++i) {
    cout << data[i];
}
挽心 2024-12-28 08:58:04

使用 boolalpha 标志,如下所示:

for (int i = 0; i < arrayLength; ++i) {
    cout << boolalpha << data[i] << endl;
}

Use the boolalpha flag, like this:

for (int i = 0; i < arrayLength; ++i) {
    cout << boolalpha << data[i] << endl;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文