error C2061: syntax error : identifier 'p',为什么呢,求高手指点

小牛吖吖 2011-03-20 02:55:20
// perm.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
using std::string;
int main(int argc, char* argv[])
{
// printf("Hello World!\n");
string s("abcde");
string *p;
p=&s;
int i=3;
string del_i(int i, p);
return 0;
}
string del_i(int l,string*m)
{
int j;
for(j=0;j!=m->length()-2;j++)
{
if(j<l)m[j]=m[j];
else m[j]=m[j+1];
}
return *m;
}


...全文
246 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
yinquan8241 2011-03-21
  • 打赏
  • 举报
回复
数组越界,当然不能read哪
[Quote=引用 6 楼 witwolf 的回复:]
前面的可以去掉
后面的可以改成
m[j-1]=m[j];
[/Quote]
小牛吖吖 2011-03-20
  • 打赏
  • 举报
回复
还是不行呐,“…………。内存不能为‘read’”。为什么呢
Al_Ways 2011-03-20
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
using std::string;
int main(int argc, char* argv[])
{
// printf("Hello World!\n");
string s("abcde");
string *p;
p=&s;
int i=3;
string del_i(int i, p); //你这句是前置声明!!
return 0;
}
string del_i(int l,string*m)
{
int j;
for(j=0;j!=m->length()-2;j++)
{
if(j<l)m[j]=m[j];
else m[j]=m[j+1];
}
return *m;
}



string del_i(int i, p);
应改成string del_i(int i,string* p);
witwolf 2011-03-20
  • 打赏
  • 举报
回复
前面的可以去掉
后面的可以改成
m[j-1]=m[j];
witwolf 2011-03-20
  • 打赏
  • 举报
回复
if(j<l)
m[j]=m[j];
else
m[j]=m[j+1];
这两句你好好看看
小牛吖吖 2011-03-20
  • 打赏
  • 举报
回复
为什么程序运行会出错呢,编译连接通过了

[Quote=引用楼主 lalison 的回复:]
// perm.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
using std::string;
int main(int argc, char* ……
[/Quote]
witwolf 2011-03-20
  • 打赏
  • 举报
回复
string del_i(int i, p);
把int去掉
这是函数调用
小牛吖吖 2011-03-20
  • 打赏
  • 举报
回复
谢谢了,大哥
yyg990441 2011-03-20
  • 打赏
  • 举报
回复

#include<iostream>
#include<string>
using namespace std;
using std::string;
string del_i(int l,string*m);
int main(int argc, char* argv[])
{
// printf("Hello World!\n");
string s("abcde");
string *p;
p=&s;
int i=3;
del_i(i, p);
return 0;
}
string del_i(int l,string*m)
{
int j;
for(j=0;j!=m->length()-2;j++)
{
if(j<l)m[j]=m[j];
else m[j]=m[j+1];
}
return *m;
}

65,190

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧