Skip to content

Instantly share code, notes, and snippets.

What would you like to do? Boilerplate template for reading from STDIN and writing to STDOUT for Objective-C
#import <Foundation/Foundation.h>
@interface HRSTDIOReadWriter : NSObject
@implementation HRSTDIOReadWriter
+(NSString*) readFromSTDIN
NSFileHandle *kbd = [NSFileHandle fileHandleWithStandardInput];
NSData *inputData = [kbd readDataToEndOfFile];
NSString *inputString = [[NSString alloc] initWithData:inputData
return inputString;
+ (void) writeToSTDOut:(NSString*) outputString
NSFileHandle *stdOut = [NSFileHandle fileHandleWithStandardOutput];
NSData* outData = [outputString dataUsingEncoding:NSUTF8StringEncoding];
[stdOut writeData:outData];
int main(int argc, const char * argv[]) {
@autoreleasepool {
[HRSTDIOReadWriter writeToSTDOut:[HRSTDIOReadWriter readFromSTDIN]];
return 0;

This comment has been minimized.

Copy link

aakash5454 commented Jan 3, 2016

this works, but I really suggest going about this way: &Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.