swift char* + int 怎么写?

在oc中 char * 可以直接加上 int swift中改怎么写?

char * buf = (char *)malloc(_pFrame->width * _pFrame->height * 3 / 2);
int a = 0

buf + a

怎么用swift写 buf + a?

阅读 3.4k
1 个回答

Swift 3.0 (2.x没有试过, 但是思路应该是一样的)


import Foundation

// alloc
let buff = UnsafeMutablePointer<CChar>.alloc(1)

// 赋值
buff.memory = CChar(integerLiteral: 8)

// 计算
print(buff.memory + 2)

// 销毁
buff.destroy()

// 释放
buff.dealloc(1)
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题