c++中的string
来源:互联网 发布:unix网络编程卷2 pdf 编辑:程序博客网 时间:2024/05/22 13:50
#include <iostream>#include <fstream>using namespace std;struct student{string name; int num; int age; char sex;};int main( ){student stud[3]; int i; ifstream infile("F:\\stud.dat",ios::binary); if(!infile) {cerr<<"open error!"<<endl; abort( ); } for(i=0;i<3;i++)infile.read((char*)&stud[i],sizeof(stud[i])); infile.close( ); for(i=0;i<3;i++) {cout<<"NO."<<i+1<<endl; cout<<"name:"<<stud[i].name<<endl; cout<<"num:"<<stud[i].num<<endl; cout<<"age:"<<stud[i].age<<endl; cout<<"sex:"<<stud[i].sex<<endl<<endl; } return 0; }Compiling...stu.cppF:\stu2\stu.cpp(23) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)Error executing cl.exe.stu.obj - 1 error(s), 0 warning(s)
解决方式:
#include <iostream>#include <fstream>#include <string> //加入这行using namespace std;如果没有包含<string>的话,cout不支持string类型的数据
0 0
- c/c++中的string
- c中的string函数
- c中的string
- c语言中的String库
- C语言中的String库函数
- c语言中的String库
- C++中的string与C中的char*
- C中的char[]与C++中的string
- c#中的string.format方法使用秘笈
- C语言string.h中的函数
- C#:String类型中的CharAt 方法
- string在C和C++中的用法
- C++String 类中的常用函数
- 【C++】String类中的运算符重载
- 模拟实现C++STL中的string类
- 【C/C++】标准C++中的string类的用法总结
- C/C++头文件一览 &&string.h中的函数
- asp.net(C#)中的DBNull、Null、String.Empty等
- DFB GTK WEBKIT移植
- Python的中文处理
- 独立第三天
- Java字符串分割与高效的charAt方法
- Eclipse调试,以及JUnit测试工具用法
- c++中的string
- 电子商务网站搜刮引擎优化规复之路
- 九度OJ 1550 分糖果
- 菜鸟之 初学EJB
- 第一天
- Comparable与Comparator之比较
- 【日志】2014_4_2 git submodule & grep & vs & ant
- 开篇大典
- Java快速排序