再发一贴, 字符串数组的有关问题
再发一贴, 字符串数组的问题~
全部代码
#include <iostream>
#include <string.h>
using namespace std;
void main()
{int year,month,day;
string week[7]={ "Sunday ", "Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday "};
cout < < "please enter year month day: " < <endl;
cin> > year> > month> > day;
while(year!=0&&month!=0&&day!=0)
{
int total;
int year_num(int x);
int month_num[12] = {0,3,3,6,1,4,6,2,5,0,3,5};
if (((year%4==0&&year%100!=0)||(year%400==0))&&(month> 2))
{
month_num[(month - 1)]+=1;
}
total= year_num(year) + month_num[(month - 1)] + day;
cout < <week[total%7] < <endl;
cout < < "please enter year month day: " < <endl;
cin> > year> > month> > day;
}
}
int year_num(int x)
{
int sum=0,i,j=0;
for(i=1;i <x;i++)
{
if ((i%4==0&&i%100!=0)||(i%400==0))
{
sum+=366;
}
else
{
sum+=365;
}
}
return (sum);
}
错误提示如下
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.
------解决方案--------------------
#include <string.h> 改为 #include <string>
全部代码
#include <iostream>
#include <string.h>
using namespace std;
void main()
{int year,month,day;
string week[7]={ "Sunday ", "Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday "};
cout < < "please enter year month day: " < <endl;
cin> > year> > month> > day;
while(year!=0&&month!=0&&day!=0)
{
int total;
int year_num(int x);
int month_num[12] = {0,3,3,6,1,4,6,2,5,0,3,5};
if (((year%4==0&&year%100!=0)||(year%400==0))&&(month> 2))
{
month_num[(month - 1)]+=1;
}
total= year_num(year) + month_num[(month - 1)] + day;
cout < <week[total%7] < <endl;
cout < < "please enter year month day: " < <endl;
cin> > year> > month> > day;
}
}
int year_num(int x)
{
int sum=0,i,j=0;
for(i=1;i <x;i++)
{
if ((i%4==0&&i%100!=0)||(i%400==0))
{
sum+=366;
}
else
{
sum+=365;
}
}
return (sum);
}
错误提示如下
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.
------解决方案--------------------
#include <string.h> 改为 #include <string>