2015-10-05 43 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我不這麼認爲,「一個單詞中間的句子」聽起來像在句子中的某處,不一定是中心詞 –