有关大小写的c++帮助
C++ help related to Upper and Lower cases
我想让代码搜索句子中间的单词,看看它的第一个字母是否小写。
如果是,则将其变为大写。例如:John讨厌每天使用c++,这会把c++中的c改为大写。
代码
#include <iostream>
#include <string>
#include<cstdlib>
#include<fstream>
using namespace std;
ifstream in_stream;
ofstream out_stream;
int main()
{
in_stream.open("in.dat");
out_stream.open("out.dat");
char s[256];
in_stream>>s;
s[0] = tolower(s[0]);
out_stream<<s;
in_stream.close();
out_stream.close();
system("Pause");
return 0;
}
重新定义s
为std::string
类型
std::string wordOfInterest = "c++" // Change as per your needs
std::string::size_type pos = s.find(wordOfInterest); // Index at which the word of interest starts
if (pos != std::string::npos) s[pos] = toupper(s[pos]); // Updating the value at index with its upper case counterpart
相关文章:
- 需要帮助设置在C++中使用的Potrace
- 在指针的帮助下,文本文件中单词的频率
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 如何在Qbutton的帮助下更改Q对话框的宽度
- 需要帮助将结构数组传递给函数
- C++需要帮助从用户那里获得一个整数,并确保它在另外两个整数之间
- 需要帮助在 c++ 中将字符串转换为字符 ----错误 "const char *" 类型的值不能用于初始化 "char" 类型的实体
- 有人可以帮助我处理正则表达式吗?
- C++调用具有 *this 属性的单个帮助程序函数
- C++:需要帮助了解运算符重载错误
- 需要以下代码的帮助,下面的代码有什么问题
- CS1 项目帮助C++
- 用于检查值是否为其任何参数的帮助程序函数
- 需要有关此 if 语句的帮助
- 类型限定宏帮助程序
- CoreCLR 中的检测探查器 - 将帮助程序程序集加载到 dotnet 进程的方法
- NS3 插槽混淆(需要帮助理解)
- 设计帮助 - 为不同类型的消息处理通用接口的设计模式
- 需要帮助查找内存泄漏
- 有人可以帮助我理解这些参数/参数吗?