读书人

字符串数组的有关问题

发布时间: 2012-03-08 13:30:13 作者: rapoo

字符串数组的问题~
我定义一个数组,一个整型数结果出错
string week[7]={ "Sunday ", "Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday "};
int n=100;
cout < <week[n%7];

出现如下错误
帮下忙
F:\days.cpp(25) : 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)


[解决办法]
很明显你这个是算星期几的程序,但是你对头文件中的理解有问题,你这个程序头文件应该改为:
#include <iostream>
#include <string>

using namespace std;
这样就可以通过程序了,#include <string.h> 这个文件是旧的标准,建议你使用新标准,#include <cstring> 这两个文件中的宏定义是不一样的...

读书人网 >C++

热点推荐