我想使用strlen()在需要int值的函数中返回的数字.
functionName((strlen(word)+strlen(otherWord)+1));
Run Code Online (Sandbox Code Playgroud)
这段代码不起作用,因为它们返回size_t.
有没有办法将结果转换为int所以我可以进行加法运算并将它们用作int?
大多数其他答案都使用C风格的转换,你不应该在C++中做:你应该静态转换.
functionName( static_cast<int>((strlen(word)+strlen(otherWord)+1));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1637 次 |
| 最近记录: |