string 和 cstring

今天在看C++PRIMER做课后题的时候突然发现一个小问题,题目是3.23,起先自编的代码如下 

Code:
  1. #include <iostream>   
  2. #include <bitset>   
  3. #include <cstring>   
  4. using namespace std;   
  5. void main()   
  6. {   
  7.     bitset<64> bitvec(32);   
  8.     cout<<bitvec<<endl;   
  9.     bitset<32> bv(1010101);   
  10.     cout<<bv<<endl;   
  11.     string bstr;   
  12.     cin>>bstr;   
  13.     bitset<8> bv2(bstr);   
  14.     cout<<bv2<<endl;   
  15. }  

结果出现一个错误 -------------------Configuration: 3_23 - Win32 Debug-------------------- Compiling... 3_23.cpp d:/c++学习/c++ primer 课后练习/3_23/3_23.cpp(12) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits,class std::allocator >' (or there is no acce ptable conversion) 执行 cl.exe 时出错. 3_23.exe - 1 error(s), 0 warning(s) 搞的我不明不白的,简简单单输入或输出一个string类的对象都会出错,很无奈,只能上网查查。十几分钟后大概有了结果,看别人写的程序好像都是

Code:
  1. #include<string>  

而非cstring。但我记得我学C++的时候老师教我的就是Cstring,当时还花了不少功夫去记呢,不禁觉得很奇怪。我把我的cstring改成string后,果然就成功运行了,毛病就出在这个头文件上。可是到底这两个头文件有什么区别呢?我虽然很好奇但是由于水平有限暂时没办法了解,希望知道的朋友能告诉我。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值