自己写一个字符串的类,这个为什么总是会输出的字符串比输入的少第一个字符?
class my_string{
public:
char *str;
int len;
void inti_string(){
str=new char[255];
len=0;
}
void input(int);
void substring(my_string &sub,int pos,int len);
int strcomp(my_string b);
int index(my_string s,my_string t,int pos);
};
void my_string::input(int lenl){
char c;
cin>>c;
this->len=lenl;
// gets(this->str);
cin>>this->str;
// cout<str<
printf("%s",this->str);
}
这个输入和输出换了个遍,好像一直是输出的字符串比输入的少第一个字符。
你的input函数中的第一个cin会把第一个输入的字符串吃掉,所以str会少一位