24小时热门版块排行榜    

查看: 458  |  回复: 1

赵建成

木虫 (小有名气)

[求助] 虽然简单,但还是不会,求大神帮帮忙! 已有1人参与

有点小问题,不知道如何改,人家说cin>>p>>'\n';  cin>>d>>endl;这两句错了
D:\c\c\islonger\test.cpp(9) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'const char' (or there is no acceptable conversion)
D:\c\c\islonger\test.cpp(10) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)
     

这是代码:
  s.cpp
#include <iostream>
using namespace std;
#include "s.h"

bool islonger(char *s1,char *s2)
{
        int len1,len2;
        char *p2=s2;
        char *p1=s1;
        bool b;
                for(;*p1!='\0';p1++)
                len1=p1-s1;       
               
                for(;*p2!='\0';p2++)
                len2=p2-s2;
       
                b = (len1>len2);
                cout<<b<<'\n';
return 0;
}
     

      s.h
#ifndef _STRING_H_
#define _STRING_H_
//#include <stdio.h>
bool  islonger(char *s1,char *s2);
#endif

test.cpp
#include "s.h"
#include <iostream>
using namespace std;
int main()
{
         char *p,*d;
         cin>>p>>'\n';
        cin>>d>>endl;
        islonger(p,d);
        return 0;
}
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

fighter0593

金虫 (小有名气)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
赵建成: 金币+20, ★★★很有帮助 2014-08-07 15:51:48
这个你在test.cpp里面声明的是char*指针啊,没有分配内存空间。所以运行的时候会出错,另外你sin的用法不对,和cout用法不是一样的。 我把test.cpp代码改了下,可以跑了。

#include "s.h"
#include <iostream>
using namespace std;
int main()
{
        char *p,*d;
        char array1[10];//注意这个是分配内存空间,再把p指针指向它
        char array2[10];
        p=array1;
        d=array2;
        cin>>p;
        cin>>d;
        islonger(p,d);
        getchar();
        return 0;
}
2楼2014-08-07 11:11:36
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 赵建成 的主题更新
信息提示
请填处理意见