0

有人可以告诉我在 iOS 5.x -> Objective-C++ 上使用二元流的Poco::BinaryReaderPoco::BinaryWriter的用法示例吗?

昨天我发送了关于“如何创建和使用 C++ 类”的问题,但它没有回答我上面的问题。

Poco 社区论坛和 OpenFrameworks 论坛看起来像死了,所以我在这里。

谢谢。

4

1 回答 1

0

好吧,没有人愿意帮忙。

在上帝的帮助下,我自己做到了。

下载OpenFrameworks并配置到您的目标项目;

代码示例:

#import "AppDelegate.h"
#import "Poco/MemoryStream.h"
#import "Poco/BinaryWriter.h"
#import "Poco/BinaryReader.h"

@implementation AppDelegate{
    Poco::BinaryWriter *_myBinaryWriter;
    Poco::BinaryReader *_myBinaryReader;
}

@synthesize window = _window;

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.rootViewController = [[UIViewController new] autorelease];

    int bufferSize = 512;    
    char *_buffer = (char *)malloc(bufferSize);

    // >> WRITE BLOCK <<   
    Poco::MemoryOutputStream *outStream = new Poco::MemoryOutputStream(_buffer, bufferSize);

    _myBinaryWriter = new Poco::BinaryWriter(*outStream);
    (*_myBinaryWriter) << 1234567890;
    (*_myBinaryWriter) << (std::string)"some string";
    (*_myBinaryWriter) << 3.14f;
    delete(_myBinaryWriter);
    delete(outStream);

    // >> READ BLOCK <<   
    Poco::MemoryInputStream *inStream = new Poco::MemoryInputStream(_buffer, bufferSize);

    _myBinaryReader = new Poco::BinaryReader(*inStream);

    int i = 0;
    std::string s;
    float f = .0f;

    (*_myBinaryReader) >> i >> s >> f;
    delete(_myBinaryReader);
    delete(inStream);

    NSLog(@"ReadInt = '%i'", i);
    NSLog(@"ReadString = '%@'", [NSString stringWithUTF8String:s.c_str()]);
    NSLog(@"ReadFloat = '%f'", f);

    [self.window makeKeyAndVisible];
    return YES;
}

@end

我有美好的一天吗:)

于 2012-06-07T09:24:05.400 回答