以数字33188为例
string temp;
string::iterator it = temp.begin();int i;
for ( i= 0; i < 9; i++)
{
if ((33188 >> i) & 0x1 )
{
if (0 == i % 2)
{
temp.insert(it, 1, 'r');
}
else if ( 1 == i % 2)
{
temp.insert(it, 1, 'w');
}
else if ( 2 == i % 2)
{
temp.insert(it, 1, 'x');
}
}
else
{
temp.insert(it, 1, '-');
}
}
cout<<temp<<endl;
本文介绍了一种使用位操作来生成文件权限字符串的方法。通过右移和按位与操作判断特定位置上的比特是否为1,进而决定插入字符'r'、'w'、'x'还是'-'到字符串中。这种方法常用于文件系统的权限设置。
743

被折叠的 条评论
为什么被折叠?



