| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 863 人关注过本帖
标题:程序的错误
只看楼主 加入收藏
初学遍程
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-4-20
收藏
 问题点数:0 回复次数:3 
程序的错误

以下是我模仿其他的程序写的,可运行时总是显示有为
--------------------Configuration: Cexample3_163 - Win32 Debug--------------------
Compiling...
Cexample3_163.cpp
E:\something\200542625347542\C++应用编程200例\cp3\Cexample3_163\Cexample3_163.cpp(27) : error C2660: 'strcmp' : function does not take 3 parameters
E:\something\200542625347542\C++应用编程200例\cp3\Cexample3_163\Cexample3_163.cpp(46) : error C2660: 'strcmp_put' : function does not take 3 parameters
Error executing cl.exe.

Cexample3_163.obj - 2 error(s), 0 warning(s)
我不知道哪里错的,请各位高手给指点一下,谢谢你啊





程序如下:

#include<iostream.h>
#include<string.h>

void str_input(char* p1,char* p2)
{
cout<<"string1:";
cin>>p1;
cout<<"string2:";
cin>>p2;
}

void strcmp_put(char* p1,char* p2)
{
cout<<"strcmp():"<<endl;
int result=strcmp(p1,p2);
if(result>0)
cout<<p1<<"greater than"<<p2<<endl;
if(result<0)
cout<<p1<<"less than"<<p2<<endl;
if(result==0)
cout<<p1<<"identical"<<p2<<endl;
}

void strncmp_put(char* p1,char* p2,size_t count)
{
cout<<"strncmp():"<<endl;
int result=strcmp(p1,p2,count);
if(result>0)
cout<<p1<<"greater than"<<p2<<endl;
if(result<0)
cout<<p1<<"less than"<<p2<<endl;
if(result==0)
cout<<p1<<"identical to"<<p2<<endl;
}

void main(void)
{
char str1[80],str2[80],p;
int i;

for(i=1;i<=3;i++)
{
str_input(str1,str2);
strcmp_put(str1,str2);
strcmp_put(str1,str2);
strcmp_put(str1,str2,3);
cout<<"-------------------"<<endl;
}
}

搜索更多相关主题的帖子: does something function 
2006-04-28 13:13
柳儿
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:1830
专家分:30
注 册:2004-9-23
收藏
得分:0 
'strcmp' 这个函数的参数只有两个,楼主要用3个的,需要自己重新定义。

成功会使人骄傲。如果你骄傲自大,你就会停止学习。不学习,人就停止了进步
2006-04-28 14:21
ot1122
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-4-20
收藏
得分:0 
  你重载函数void strncmp_put(char* p1,char* p2,size_t count)时,
size_t count中的size_t是什么类型啊!!!
你在程序前面好象没有tepdef啊::
2006-04-28 18:57
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
以下是引用初学遍程在2006-4-28 13:13:00的发言:

以下是我模仿其他的程序写的,可运行时总是显示有为
--------------------Configuration: Cexample3_163 - Win32 Debug--------------------
Compiling...
Cexample3_163.cpp
E:\something\200542625347542\C++应用编程200例\cp3\Cexample3_163\Cexample3_163.cpp(27) : error C2660: 'strcmp' : function does not take 3 parameters
E:\something\200542625347542\C++应用编程200例\cp3\Cexample3_163\Cexample3_163.cpp(46) : error C2660: 'strcmp_put' : function does not take 3 parameters
Error executing cl.exe.

Cexample3_163.obj - 2 error(s), 0 warning(s)
我不知道哪里错的,请各位高手给指点一下,谢谢你啊





程序如下:

#include<iostream>
#include<cstring>
using std::cout;using std::cin;using std::endl;

void str_input(char* p1,char* p2)
{
cout<<"string1:";
cin>>p1;
cout<<"string2:";
cin>>p2;
}

void strcmp_put(char* p1,char* p2)
{
cout<<"strcmp():"<<endl;
int result=strcmp(p1,p2);
if(result>0)
cout<<p1<<"greater than"<<p2<<endl;
if(result<0)
cout<<p1<<"less than"<<p2<<endl;
if(result==0)
cout<<p1<<"identical"<<p2<<endl<<endl;
}

void strncmp_put(char* p1,char* p2,size_t count)
{
cout<<"strncmp():"<<endl;
int result=strncmp(p1,p2,count); //strcmp的借口是2个参数,要用strncmp。
if(result>0)
cout<<p1<<" greater than "<<p2<<endl;
if(result<0)
cout<<p1<<" less than "<<p2<<endl;
if(result==0)
cout<<p1<<" identical to "<<p2<<endl<<endl;
}

void main()
{
char str1[80],str2[80],p;
int i;

for(i=1;i<=3;i++)
{
str_input(str1,str2);
strcmp_put(str1,str2);
//strcmp_put(str1,str2); 这一句和上面的重复了,没用。
strncmp_put(str1,str2,3); //这里也不小心写掉了!
cout<<"-------------------"<<endl;
}
}


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-04-28 19:00
快速回复:程序的错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012953 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved