Today I eat bread. Today I eat cookies.
輸出:
eat: 2
I: 2
Today: 2
bread: 1
cookies: 1
我不得不做出這樣的計算的次數,一個字一個程序發生在輸入中。然後,如果某些詞之間的次數相等,則按字母順序顯示它們。到現在爲止,我這樣做:
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int countt (string text);
int main() {
string text;
while (getline(cin,text)) //Receive the input here
countt(text); //Send the input to countt
return 0;
}
int countt (string text) {
int i,j;
string aux; //I make a string aux to put the word to compare here
for (std::string::const_iterator i = text.begin(); *i != ' '; i++){
for (std::string::const_iterator j = aux.begin(); j != text.end(); j++)
*j=*i; //But here an error is given: 25:9: error: assignment of read-only location ‘j.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<const char*, std::basic_string<char> >()’
}
}
非常感謝提前。
每次使用調試器並試圖自己找到bug的來源將會使你成爲一個*自給自足的編程器*。相比之下,每次出現錯誤時尋求幫助都會降低*解決問題的能力*。 – Drop