Page 1 of 1

#include <string>

Posted: Sat Jan 14, 2006 9:40 am
by Peter3109
I seem to get compile error whenever I include <string>. I am sure that I have used it before, has something changed?

Thx.

Peter

Posted: Sat Jan 14, 2006 11:23 am
by mamun
Post your code. At least the top portion.

Posted: Sun Jan 15, 2006 8:12 am
by Peter3109

Code: Select all

#include <iostream>
#include <set>
#include <string>
using namespace std;

set<string> words;
string word;
string inword;

void add() {
	int j = 0;

	word.clear();
	for(int i = 0; i < inword.size(); i++) {
		if(inword[i] >= 'A' && inword[i] <= 'Z')
			inword[i] += 'a' - 'A';
	}
	
	while(inword[j] < 'a' || inword[j] > 'z')
		j++;
	while(inword[j] >= 'a' && inword[j] <= 'z'){
		word.push_back(inword[j]);
		j++;
	}
	words.insert(word);
	return;
}


int main() {
	while(cin>>inword)
		add();
	for(set<string>::iterator itr = words.begin(); itr != words.end(); itr++)
		cout<<*itr<<"\n";
	return 0;
}
Any help appreciated!!

Peter

Posted: Sun Jan 15, 2006 8:46 am
by mamun

Code: Select all

word.clear();
string.clear() isn't allowed in OJ.

Posted: Sun Jan 15, 2006 9:20 am
by Peter3109
Thanks!