c++ - 打印包含指定子字符串的所有字符串

标签 c++ c

我是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/

相关文章:

C语言:“Else without a previous if”使用else-if语法计算线性系统的解时

c - 难以理解指针在 c 中的工作原理

c++ - 微型过滤器从用户模式应用程序接收恒定值

c++ - g++ : error: `pkg-config: No such file or directory

c++ - Constexpr:将字符串 View 列表转换为字符数组列表

c++ - 第一个 c++ 可能出现的语法错误

c - 函数 sbrk( ) 的隐式声明

C++ 数组迭代

c++ - 转发模板参数

c++ - 监控单个程序的 CPU 和磁盘利用率