multiple functions not working

I just submitted an assignment where i was to apply multiple functions to a c++11 array. My code would run fine as long as i only applied one function to the array. Any help on understanding what i am leaving out would be appreciated

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  using namespace std;

int main(int argc, char** argv) 
{//top of main
    array<string,10>bowl;
    ifstream infile("c:\\c++data\\bowlers1.txt");
    if(!infile)//verify file is found
    {//top of verify if
        cout<<"cannot open file.";
        cout<<"This program will terminate.";
        return 1;
    }//bottom of verify if
    for(int r=1;r<=10;r++)
    {
        getline(infile,bowl[r]);
    }
    infile.close();
    for(string s:bowl)
        cout<<s<<endl;
    cout<<"The array size is "<<bowl.size()<<endl;
    sort(bowl.begin(),bowl.end());
    cout<<"Sorted A to Z:\n";
    for(string s:bowl)
        cout<<s<<endl;
    sort(bowl.rbegin(),bowl.rend());
    cout<<"Sorted Z to A:\n";
    for(string s:bowl)
        cout<<s<<endl;
    cout<<bowl.at(3)<<endl;
    bowl.fill("*");
    for(string s:bowl)
        cout<<s<<endl;
    return 0;
}
Arrays are indexed from 0 in c++. In your case the indices will be 0 to 9. Thus, lines 13-16 will cause you to access arrays beyond their bounds.
Topic archived. No new replies allowed.