注册 登录
编程论坛 C++教室

哪里错了。新手求教。

未未来 发布于 2013-01-29 16:27, 369 次点击
程序代码:
#include<iostream>
#include <string>

using namespace::std;
int main(){
string st;
cout<<"Enter the string.";
cin>>st;
char *ch=new char[st.size()+1];
char *ch=st.c_str();
delete[]ch;
return 0;
}
4 回复
#2
yuccn2013-01-29 18:56
char *ch=new char[st.size()+1];
 char *ch=st.c_str();

定义两次了。
把 char *ch=st.c_str();
改成strcpy(ch,st.c_str);
试试
#3
zhuanjia02013-01-31 13:35
using namespace std;//不要作用域运算符
int main(){
string st;
cout<<"Enter the string.";
cin>>st;
char *ch=new char[st.size()+1];
ch=st.c_str();//char *ch重复定义
delete[]ch;
return 0;
}
#4
kym僵尸2013-02-14 10:27
char *ch=st.c_str();
这一句是神马意思╮(╯▽╰)╭
#5
liqingqinger2013-02-16 11:28
指针
1