2015-10-05 12 views
-2

我希望代码能够搜索单词中间句子,并查看它的第一个字母是小写字母。与大写和小写相关的C++帮助

如果是这样,那么它就是大写。例如:约翰讨厌每天使用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; 
} 
+2

这是雁在这里被 http://stackoverflow.com/questions/313970/how-to- convert-stdstring-to-lower-case – teivaz

+2

为什么代码中存在空白链接?没有缩进?你为什么使用'char'数组? –

+0

@teivaz没有提及如何找到字符串的中间部分...但我确定这是一个不同的答案 –

回答

1

重新定义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 
+0

他想要中间的单词...找不到功能 –

+2

@SethKitchen我不这么认为,“一个单词中间的句子”听起来像在句子中的某处,不一定是中心词 –