我是c++初学者。我正在尝试实现一个小的 C++ 代码来娱乐。
程序从包含我所有 friend 姓名的文本文件中读取输入。
该程序的目的是返回/打印以指定字母/昵称开头的所有名称
例如
Nick
Joseph
Jack
Robert
Paul
David
如果我输入“J”,结果应该是 Joseph 和 Jack
如果我输入“P”或“pa”,结果应该是 paul
任何人都可以指导我让逻辑正确吗?提前谢谢了。
问候, 帕万
最佳答案
这个逻辑是这样的:
read the desired prefix from user
repeat
read one line from file
if the line starts with the desired prefix print it
until there are no more lines
关于c++ - 打印包含指定子字符串的所有字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22105187/