大家帮帮忙哈

zhenzhizhe 2008-04-01 10:27:22
#include <iostream>
using namespace std;
void main ()
{
int str[200];
int t=0,k;
{
for(int n=0;n<=200;n++)
str[t++]=n*n;
}

{
for(int i=0;i<100;i++)
{
k=strlen(str[i]);
for(int j=0;j<k;j++)
if(str[i]==str[--k])

cout<<str[i]<<endl;
}
}
}
//--------------------Configuration: 013 - Win32 Debug--------------------
Compiling...
013.cpp
G:\学习\编程\013\013.cpp(15) : error C2664: 'strlen' : cannot convert parameter 1 from 'int' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.


数组中的元素不能求长度吗?
如果要求出长度,该怎么办?
...全文
45 8 打赏 收藏 举报
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhenzhizhe 2008-04-01
  • 打赏
  • 举报
回复

知道了,忘了用sizeof(int),
呵呵
谢了
enewell 2008-04-01
  • 打赏
  • 举报
回复

k=strlen(str[i]);
这句话想干什么?
str的长度还是str[i]的长度?
如果是前者,保存一个记录长度的变量
如果是后者,就是sizeof(int)吧
zhenzhizhe 2008-04-01
  • 打赏
  • 举报
回复
再问一下:那该怎么解决这个函数问题?
呵呵
谢谢哈
zhenzhizhe 2008-04-01
  • 打赏
  • 举报
回复
哦,str只能用于字符串数组
wuyu637 2008-04-01
  • 打赏
  • 举报
回复
up...同意楼上的。。。
不要把函数想的太神奇。
ryfdizuo 2008-04-01
  • 打赏
  • 举报
回复
sorry
str是int类型怎么能用strlen?
ryfdizuo 2008-04-01
  • 打赏
  • 举报
回复
strlen(str);
  • 打赏
  • 举报
回复
k=strlen(str[i]);
-------------->
k=strlen(str+i);
发帖
C++ 语言

6.3w+

社区成员

C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
帖子事件
创建了帖子
2008-04-01 10:27
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下