24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 464  |  回复: 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的回帖
相关版块跳转 我要订阅楼主 赵建成 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 071000生物学调剂 +7 知昭蔓 2026-04-02 7/350 2026-04-02 21:47 by dongzh2009
[考研] 材料科学与工程考研 +3 拯救皮特托先生 2026-04-02 3/150 2026-04-02 21:34 by 百灵童888
[考研] 283分材料与化工求调剂 +13 罗KAKA 2026-04-02 13/650 2026-04-02 21:16 by dongzh2009
[考研] 求调剂,一志愿郑州大学材料与化工专硕,英二数二342分,求老师收留 +8 v12abo 2026-04-02 8/400 2026-04-02 20:53 by 1104338198
[考研] 285求调剂 +8 AZMK 2026-04-02 11/550 2026-04-02 20:16 by yulian1987
[考研] 学硕机械工程303求调剂 +5 无名所以叫吴明 2026-03-30 5/250 2026-04-02 20:12 by hengsmith
[考研] 279求调剂 +5 傅文秋 2026-04-02 5/250 2026-04-02 18:10 by 笔落锦州
[考研] 301求调剂 +14 骆驼男人 2026-04-02 14/700 2026-04-02 14:08 by baoball
[考研] 初试301,代码085701环境工程,本硕一致,四六级已过,有二区一作,共发表5篇论文 +6 axibli 2026-04-01 6/300 2026-04-02 13:42 by Ecowxq666!
[考研] 求调剂,一志愿 南京航空航天大学 ,080500材料科学与工程学硕,总分289分 +11 @taotao 2026-03-29 11/550 2026-04-02 10:04 by realme321
[考研] 材料调剂 +11 一样YWY 2026-03-31 11/550 2026-04-01 22:25 by zhouyuwinner
[考研] 085601材料工程找调剂 +20 oatmealR 2026-03-29 21/1050 2026-04-01 21:00 by lijunpoly
[考研] 349求调剂 +6 吃的不少 2026-04-01 6/300 2026-04-01 17:55 by JYD2011
[考研] 0856材料化工调剂 总分330 +18 zhubinhao 2026-03-27 18/900 2026-04-01 09:37 by oooqiao
[考研] 材料与化工272求调剂 +25 阿斯蒂芬2004 2026-03-28 25/1250 2026-03-31 16:27 by hypershenger
[考研] 262求调剂 +7 ZZ..000 2026-03-30 8/400 2026-03-31 10:05 by cal0306
[考研] 一志愿华中师范化学332分求调剂 +3 Lyy930824@ 2026-03-29 3/150 2026-03-30 20:15 by DHUSHUAI
[考研] 一志愿双一流机械285分求调剂 +4 幸运的三木 2026-03-29 5/250 2026-03-29 14:49 by Miko19
[考研] 085600,专业课化工原理,321分求调剂 +5 大馋小子 2026-03-28 5/250 2026-03-29 08:56 by qingfeng258
[考研] 304求调剂 +6 曼殊2266 2026-03-27 6/300 2026-03-28 14:10 by 唐沐儿
信息提示
请填处理意见