您好我是Objective C的新手,我没有mac我在compileonline.com上使用在线编译器。今天我写了以下程序
1 #import<Foundation/Foundation.h>
2 int main(){
3 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]init];
4 NSString * firstName = @"Eric";
5 NSString * lastName = @"Simmons";
6 NSString * fullName = [[firstName stringByAppendingString: @" "]stringByAppendingString: lastName];
7 NSLog(fullName);//prints Eric Simmons
8 NSLog (@"The Entered full name is :",fullName);// Just prints The entered full name is :
9 NSString * correctFullName = [fullName stringByReplacingOccurrencesOfString: firstName withString: @"Derrick"];
10 NSLog(correctFullName);//prints Derrick Simmons
11 NSLog(@"The correct full name : ",correctFullName);// Just prints The correct full name is :
12 [pool drain];
13 return 0;
14 }
但是这个程序效果很好。但产量不是我的预期。输出看起来像这样
Executing the program....
2014-01-02 05:42:27.958 demo[18115] Eric Simmons
2014-01-02 05:42:27.959 demo[18115] The Entered full name is :
2014-01-02 05:42:27.959 demo[18115] Derrick Simmons
2014-01-02 05:42:27.959 demo[18115] The correct full name :
执行第8行和第11行时,不会打印名称。哪里出错了这是程序中的错误还是编译器中的错误。请帮忙......
答案 0 :(得分:0)
第8行&amp; 11 你忘了格式说明符
NSLog (@"The Entered full name is : %@",fullName);
NSLog(@"The correct full name : %@",correctFullName);
答案 1 :(得分:0)
您需要格式说明符才能打印字符串。
使用%@ 打印如下字符串:
NSLog (@"The Entered full name is : %@",fullName);