Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从 NSString 获取输入scanf ("%@", &str);不起作用?
scanf ("%@", &str);
scanf 将读入 C 字符串而不是 NSString (据我所知)。所以,要做你想做的事,你需要先把你的输入读入一个 C 字符串(即 str),然后把它变成一个 NString,如下所示
myString = [NSString stringWithUTF8String:str];
顺便说一句,如果 str 是一个数组,则不需要传递 str 即 &str 的地址。只需这样做:
scanf("%s",str);