Why compile error?

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
ImLazy
Experienced poster
Posts: 215
Joined: Sat Jul 10, 2004 4:31 pm
Location: Shanghai, China

Why compile error?

Post by ImLazy »

Code: Select all

#include <iostream>
#include <string>
#include <map>
#include <cctype>

using namespace std;

map<string, int> g_dict;

int main() {
    string strIn;
    while (cin >> strIn) {
        string temp;
        for(int i = 0; i < strIn.size(); i++) {
            temp += (char)tolower(strIn[i]);
            if (!isalpha(temp[i])) {
                temp[i] = ' ';
            }
        }
        strIn.clear();
        for (int i = 0; i < temp.size(); i++) {
            if (isalpha(temp[i])) {
                strIn += temp[i];
            }
        }
        g_dict[strIn] = 1;
    }
    for (map<string, int>::iterator itr = g_dict.begin();
         itr != g_dict.end();
         itr++
        ) {
        cout << itr->first << endl;
    }
    return 0;
}
I stay home. Don't call me out.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

Don't you get a mail with compiler's output?
Here are the compiler error messages:

04839136_24.c: In function `int main()':
04839136_24.c:20: no matching function for call to
`basic_string<char,string_char_traits<char>,__default_alloc_template<true,0> >::clear ()'
You can replace strIn.clear(); by strIn="";
ImLazy
Experienced poster
Posts: 215
Joined: Sat Jul 10, 2004 4:31 pm
Location: Shanghai, China

Post by ImLazy »

Thank you.
I stay home. Don't call me out.
Post Reply

Return to “C++”