【问题标题】:iOS: example of usage Poco::BinaryReader & Poco::BinaryWriteriOS:使用示例 Poco::BinaryReader & Poco::BinaryWriter
【发布时间】:2012-06-07 06:33:36
【问题描述】:

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

昨天我发送了关于“How to create and use C++ classes”的问题,但它没有回答我上面的问题。

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

谢谢。

【问题讨论】:

    标签: c++ objective-c ios poco-libraries


    【解决方案1】:

    好吧,没有人愿意帮忙。

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

    下载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
    

    我有美好的一天:)

    【讨论】:

      猜你喜欢
      • 2013-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      相关资源
      最近更新 更多