问题描述
void foo(const char* input,ostream& fout);
//foo("test",std::cout) -> "test est st t "
//foo("hi_world",std::cout) -> "hi_world i_world world orld rld ld d "
该函数仅打印字符串并每次删除第一个字符。如果删除的字符是下划线,则该功能不会打印。
这是我到目前为止所拥有的:
void foo(const char* input,ostream& fout) {
char * answer;
while(*input) {
if(*input == '_') {
//somehow do nothing
}
if(input > input[0] {
fout << *input+1
}
else {
fout << *input << " ";
}
}
解决方法
我不得不更改答案,因为我是第一次错读问题,但是我认为这将满足您的需求。
$ ./answer
test est st t
hiworld iworld world world orld rld ld d
运行此命令将产生以下输出。
pip install pyinstaller
,
您需要在循环中每次递增input
才能更改字符串的起始索引。
如果第一个字符为continue;
,请使用_
跳过迭代。
要打印字符串,请使用fout << input
。 fout << *input
只会打印一个字符,而不是整个字符串。
void foo(const char* input,ostream& fout) {
for(; *input; input++) {
if(input[0] == '_') {
continue;
}
fout << input << " ";
}
}