如标题所示,我想使用C
-样式而不是使用库string
来插入字符在char array
之后,并且请避免使用缓冲区函数,只有基本的:)。在字符数组中的特定位置插入一个字符
char sentence[100],*p = NULL;
cin.get(sentence,100);
char replaceChar; // after What character should we insert
cin>>replaceChar;
char insertingChar; // the character we are inserting after the replaceChar;
cin >> insertingChar ;
p = strchr(sentence , replace);
while(p != NULL){
//and this is I could think of ...
}
所以突然想到说,我们有这样一句话: “我要苹果”,在replaceChar = A,和insertingChar = '*';
结果应该是:“我wa * nt a * pples”。
使用'std :: string'使您的生活更轻松。 –
在您的示例中,只有1个'a's'受到影响,是否是由设计决定的? –
nope我有一个问题,当发布这个,是一个*之后的第一个'a' – JohnnyOnPc