Dictionary reader

So I'm working on this code and I think I've actually almost got it, but my compiler is telling me I'm missing "{" somewhere in the code.
#include "std_lib_facilities.h"
using namespace std;
int main()
{
vector<string> dict;
int p,count = 0;
ifstream in("/usr/share/dict/words");
copy(istream_iterator<string>(in),
istream_iterator<string>(),
back_inserter(dict));


try {
cout<<"enter the position to test\n";
cin>>p;
int check(string s,unsigned int p);
for(unsigned int i=0;i<dict.size();i++)
{
if(check(dict[i],p-1))
count++;
}
cout<<count<<" words in the dictionary have vowels [aeiou] at position "<<p<<endl;
} catch(...) {
cout << "Data Unavailable\n";
}
}

{
if(s.size()<=p)
return 0;
if(s[p]=='a' || s[p]=='e' || s[p]=='i' || s[p]=='o' || s[p]=='u')
return 1;
if(s[p]=='A' || s[p])=='E'|| s[p]=='I' || s[p]=='O' || s[p]=='U')
return 1;
return 0;
}

It's supposed to read from the dictionary and tell me how many vowels [aeiou] are in a given position. Ca anyone help me?
Last edited on
If you post with code tags and sensible indentation, it will be easier for you and us to see where you may have missed a brace:

http://www.cplusplus.com/articles/z13hAqkS/

From counting braces, I can see that you close out your main function on the second of the two braces here:

1
2
3
cout << "Data Unavailable\n";
}
} // This closes your main function 

Hi,

please use code tags

http://www.cplusplus.com/articles/jEywvCM9/

also use white-spaces, not only they make the code look neater but they also keep tab on brackets

I think somewhere near the catch() function you have added an extra bracket...
yes thank ya'll so much and I'm sorry I'm new to this.
It has stopped throwing that error but now instead of running its telling me this.


"In function `main':
hw5pr3.cpp:(.text+0x2c6): undefined reference to `check(String, unsigned int)'
collect2: error: ld returned 1 exit status"

I've never seen it before and I have no idea how to fix it.
For this error, it's saying that the compiler cannot find the prototype for function check(String, unsigned int)

Did you have an include? Do you have the prototype ABOVE main?

Joe
Concord Spark Tutor
sparkprogrammer@gmail.com
Topic archived. No new replies allowed.