我想使字符的交流風格數組指針這樣的:如何decleare char * const的的argv []中迅速
*const argv[]
我想通了,我必須使用UnsafePointer<UnsafeMutablePointer<Int8>>
但我不不知道如何初始化它。
我該如何映射這種正常的陣列來UnsafePointer<UnsafeMutablePointer<Int8>>
:
let argv = ["/usr/bin/printf", "BBB"]
謝謝
我想使字符的交流風格數組指針這樣的:如何decleare char * const的的argv []中迅速
*const argv[]
我想通了,我必須使用UnsafePointer<UnsafeMutablePointer<Int8>>
但我不不知道如何初始化它。
我該如何映射這種正常的陣列來UnsafePointer<UnsafeMutablePointer<Int8>>
:
let argv = ["/usr/bin/printf", "BBB"]
謝謝
最簡單的辦法是讓可可形成你的C字符串:
let args = ["/usr/bin/printf","BBB"]
var cs = UnsafeMutablePointer<UnsafeMutablePointer<Int8>>.alloc(2)
for (ix,s) in args.enumerate() {
cs[ix] = UnsafeMutablePointer<Int8>((s as NSString).UTF8String)
}
var cs2 : UnsafePointer<UnsafeMutablePointer<Int8>> = UnsafePointer(cs)
當心; cs
不包含副本。它的指針指向args
中的字符串。
這是無效的* const argv []',你想要做什麼? –
@iharob運行此功能==> public func execvp(_:UnsafePointer,_:UnsafePointer >) - > Int32 –
DEopen
@iharob execvp(const char * file,char * const argv []); – DEopen