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

C++诸位大神,求破解

2013-03-14 
C++各位大神,急求破解#includeiostreamusing namespace std#includestdio.h#includestring.hint ma

C++各位大神,急求破解
#include<iostream>
using namespace std;
#include<stdio.h>
#include<string.h>

int main()
{
int m,d,i,j,k;
char a[4],b[4]="0/0";
cin>>a;
while(strcmp(a,b)!=0)
{
m=atoi(a.substr (0));
d=atoi(a.substr (3,4));
if(m==8)
d+=31;
int p=0;
for(j=1;j<=10;j++)
{
if(p<d)
p+=j;
else if(p==d)
{
k=12-j;
break;
}
else
{
k=11-j;
break;
}
}
cout<<k<<endl;
cin>>a;
}
return 0;
}


错误如下:


.cpp(13) : error C2228: left of '.substr' must have class/struct/union type
急求破解 c++
[解决办法]
char * 没有 substr函数,string才有,请使用如下形式

char a[]="hello word!"
string str(a);
str.substr(,);
[解决办法]

#include<iostream>

#include<stdio.h>
#include<string.h>
#include <string>

using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
int m,d,i,j,k;
char a[4],b[4]="0/0";
cin>>a;
while(strcmp(a,b)!=0)
{
string str(a);
m=atoi(str.substr (0).c_str());
d=atoi(str.substr (3,4).c_str());
if(m==8)
d+=31;
int p=0;
for(j=1;j<=10;j++)
{
if(p<d)
p+=j;
else if(p==d)
{
k=12-j;
break;
}
else
{
k=11-j;
break;
}
}
cout<<k<<endl;
cin>>a;
}
return 0;
}



string str(a);
m=atoi(str.substr (0).c_str());
d=atoi(str.substr (3,4).c_str());
[解决办法]
引用:
楼主啊 我真是不吐不快了。。。憋死我了 你能告诉我
stdio 和 include<iostream>
一起用 是啥意思么?而且还  .h  我无语啊。



你这吐槽的有啥问题???
#include <iostream>
#include <stdio.h>
在我看来没有什么问题,如果非要遵循C++标准也只是改成
#include <iostream>
#include <cstdio>

热点排行