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

如何输入字符串指针

yjg19841211 发布于 2010-08-07 20:36, 964 次点击
#include<iostream>
using namespace std;
void iquote(int );
void iquote(double );
void iquote(const char *);
int main()
{
    int a;double b;
    cout<<"enter.....";
    cin>>a;
    cout<<"enter!!!!";
    cin>>b;
    char *p;
    cin>>*p;
    iquote(a);
    iquote(b);
    iquote(p);
    return 0;
}
void iquote(int x)
{
    cout<<x<<endl;
}
void iquote(double x)
{
    cout<<x<<endl;
}
void iquote(const char *p)
{
    cout<<p<<endl;
}
正在做一个函数重载的题,怎么输入那个字符串?
3 回复
#2
cnfarer2010-08-07 21:35
指针必须指向某个空间
#3
yjg198412112010-08-07 23:07
直接用 char *p="yjg";就行,但是我想运行是输入就不知道怎么弄
#4
cnfarer2010-08-08 06:39
要输入的话,先用malloc()分配空间,让指针指向它.
或,直接定义一个字符数组,让指针指向数组首地址.

1