利用输入字符串流istringstreambool b; string s="true"; istringstream(s)>>boolalpha>>b;//boolalpha>>必须要加 cout<<boolalpha<<b<<endl;但当字符串s为“1”时,上面的代码无法正确转换,此时应该用:string s=""; istringstream(s)>>b; cout<<boolalpha<<b<<endl;