![](/img/trans.png)
[英]Is it possible to compile both 32-bit and 64-bit configurations without restarting Visual Studio?
[英]Using for loop to reverse Iterate over elements of a container/string without warnings in both 32-bit and 64-bit
我只想在容器或字符串上反向迭代。
此示例代碼
for (int i = strlen (str) - 1; i >= 0; i--)
{
...
}
將對64位編譯發出警告:
warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
另一方面,
for (size_t i = strlen (str) - 1; i >= 0; i--)
{
...
}
由於size_t是無符號的,將導致無限循環。
我知道我可以使用其他技術, 但是我只想使用簡單的for循環!
如何為32位和64位編譯編寫干凈的代碼?
改成:
for (size_t i = strlen (str); i--; )
{
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.