C++ strings
1
Name:
Anonymous
2010-11-26 9:22
Hey /prog/,
I need your help. I'm a beginner in C++ and I've been doing some exercises. I got stuck when asked to find a word made only with vowels. So far my program can find all vowels in the text but I've no idea how check if a word consists only of vowels.
I'm working with STL strings. I've tried google but everything's too confusing to me atm.
Please help.
2
Name:
Anonymous
2010-11-26 9:23
The D Programming Language
3
Name:
Anonymous
2010-11-26 9:25
int i;
char allVowels = 1;
for(i = 0; i < strLength; ++i){
if(! isVowel(str[i])){
allVowels = 0;
break;
}
}
if(allVowels){
//do whatever
}
STRINGS? WHAT ARE THESE STRINGS YOU SPEAK OF?
4
Name:
Anonymous
2010-11-26 9:27
>>3
Using char instead of _Bool or int.
IHBT.
5
Name:
Anonymous
2010-11-26 9:30
>>4
why would i use 4 bytes when i can use 1?
and bool? lol, this is C, not java.
6
Name:
Anonymous
2010-11-26 9:34
OP here.
Maybe this will help:
void FindWord (string S) {
string word;
string::size_type start(0);
string::size_type end;
end = S.find_first_of(Cdelim, start);
while(end != string::npos) {
word = S.substr(start, end - start);
CheckWord(word);
start = end + 1;
end = S.find_first_of(Cdelim, start);
}
word = S.substr(start);
CheckWord(word);
}
void CheckWord (string Z) {
size_t found;
string word;
found = Z.find_first_of(Cvowels);
while(found != string::npos) {
word = Z[found];
found = Z.find_first_of(Cvowels, found+1);
}
cout << word ;
cout << endl;
}
7
Name:
Anonymous
2010-11-26 9:50
>>5
Don't come crying to me when your critical loops are slow as molasses
8
Name:
Anonymous
2010-11-26 10:10
int f(char *s) { return !s[strspn(s, "aeiou")]; }
9
Name:
Anonymous
2010-11-26 10:43
>>7
>critical loops
>OP is clearly doing simple string exercises
YHBT
10
Name:
Anonymous
2010-11-26 10:45
>>9
No sage, incorrect invocation of the quote environment, I think this
guy might be from the imageboards.
11
Name:
Anonymous
2010-11-26 10:47
>>10
i am not a bbcode master
12
Name:
Anonymous
2010-11-26 11:09
>>11
Hint:
It's not BBCode.
13
Name:
Anonymous
2010-11-26 11:34
>>1
:3 mfw I realise that innocent soul of OP is currently being corrupted by C++ strings. No
\b[aoieu]+\b regexpes for him!
:3:3:3
>>10
Let's fork(2) him.
14
Name:
Anonymous
2010-11-26 11:42
>>13
It's still obvious that you're from the imageboards.
15
Name:
Anonymous
2010-11-26 11:56
>>3
Have I mentioned that I advertise on
/b/ only with the purpose of giving you something todo?
16
Name:
Anonymous
2010-11-26 11:57
17
Name:
Anonymous
2010-11-26 12:00
18
Name:
Anonymous
2010-11-26 12:02
19
Name:
Anonymous
2010-11-26 12:40
20
Name:
Anonymous
2010-11-26 12:41
bool all_bowels(string::const_iterator start, end) {
return (start == end) ? true :
aintvowel(*start) ? false :
allbowels(s, ++start);}
Doesn't work? Who cares, it's Sepples.
21
Name:
Anonymous
2010-11-26 13:26
main = interact $ unlines . filter (all (`elem` "aeiouAEIOU")) . words
22
Name:
Anonymous
2010-11-26 14:31
23
Name:
Anonymous
2010-12-17 1:37
Erika once told me that Xarn is a bad boyfriend
24
Name:
Anonymous
2010-12-25 11:45