貌似很简单的问题。。两次输出为什么不一样。。
- C/C++ code
#include<iostream>#include <string>using namespace std;int main(){ char pc[8] = "我Hello"; string str = "我Hello"; string::iterator iter= str.begin(); int i = 0; while(iter != str.end()) { cout<<i<<":"<<((*iter)&(0x7f))<<endl; iter++; i++; } cout<<str.c_str()<<endl;////输出string for(int i = 0;i<7;i++) { pc[i]= pc[i]&0x7f; }//下面输出数组。。。 for(int i = 0;i<7;i++) { cout<<pc[i]; } cout<<endl; char pause; cin>>pause; return 0;}[解决办法]
cout<<i<<":"<<((*iter)&(0x7f))<<endl; 这里*iter没改
pc[i]= pc[i]&0x7f; 这里pc[i] 改了