Standard input/output in Objective-C
Standard input/output in Objective-C
- Subject: Standard input/output in Objective-C
- From: Mikael Wämundson <email@hidden>
- Date: Tue, 23 Mar 2010 22:44:40 +0100
First: Yes, I've been looking around on the net to find an answer ;)
I really like the C++ method of using cin/cout in the iostream.h when communicating via the standard input/output (i.e. the Terminal).
When doing this in Objective-C it gets, to me, very complicated. Seems I'm going wrong some way.
My first attempt is of course to just use the cin/cout methods by importing iostream.h, but when looking for the header file I find it deeply buried (/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/IOKit/stream) and I don't succeed in importing it.
My conclusion from this is: I'm not supposed to use cin/cout in an Objective-C application???
Second attempt is to use Objective-C methods like:
NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardInput];
NSData *inputData;
NSString *inputString;
Person *aPerson = [[Person alloc] init];
printf("Type the persons first name: ");
inputData = [fileHandle availableData];
inputString = [[NSString alloc] initWithData: inputData encoding:NSUTF8StringEncoding];
[aPerson setPersonsFirstName: inputString];
Feels complicated. My conclusion: I'm making it more complicated than it should be???
Happy for feedback!
/Mikael_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden