2011-02-15 43 views
0

夥計們,讓我們說一句我怎樣才能用Visual C++將一個句子分成單詞

string sentence =「你好,我喜歡C++編程語言!

,我希望把每個字到字符串數組...我想我可以用一個分隔符

size_t space = sentence.find(" "); 
string words[]; //putting individual words here 
for(int i=0; i < sentence.length(); i++) 
{ 
    words[i] = 
    //incrementing delimiter to next space here 
} 

知道的任何幫助。由於

+1

檢查此http數組更好://計算器.com/questions/236129/how-to-split-a-string – Pepe 2011-02-15 06:46:41

+0

Visual C++不是一種編程語言。 P.R.已經鏈接到如何在C++中分割字符串的答案。 – 2011-02-15 06:51:22

回答

0

您可以使用算法庫副本()

string s("Your String"); 
istringstream iss(s); 
vector<string> words; 
copy (istream_iterator(iss),istream_iterator(),back_inserter(words)); 

的代碼應該是這樣的,我認爲使用Vector是不是字符串