从指针转换为指针C ++

时间:2016-04-29 11:34:14

标签: c++ casting

如果我获得指向以下代码行的指针

将会很感激

Char fileName[100] ;

strncpy(static_cast<Char *>( fileName),static_cast<const Char *>(getCurrentUser()),Int32(ML_STRING_SIZE));

我得到Lint错误:从指针转换为指针。如果我在没有静态的情况下进行投射,则会抛出C样式的错误。如果我不使用任何演员

strncpy(( fileName),(getCurrentUser()),Int32(ML_STRING_SIZE));   it throws 
array type passed to function expecting a pointer

我不确定如何修复它。

1 个答案:

答案 0 :(得分:0)

这是修复。

strncpy(( &fileName[0]),(getCurrentUser()),UInt32(ML_STRING_SIZE));
  1. First agrument&amp; fileName [0] ++ DreamLax
  2. 第二个参数返回const char *,因此无需强制转换
  3. 第三个参数应该是unsigned int。
  4. 这三个人共同解决了这个问题。

相关问题