首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

字符串数组的有关问题

2012-03-08 
字符串数组的问题~我定义一个数组,一个整型数结果出错stringweek[7]{ Sunday , Monday , Tuesday ,

字符串数组的问题~
我定义一个数组,一个整型数结果出错
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> 这两个文件中的宏定义是不一样的...

热点排行