Not sure how to proceed

I have been working with this for a while and researching what I need when I need it. I have been using the website our professor provided us with to compile and execute the program. http://www.compileonline.com/compile_cpp11_online.php. The website has been working ok so far. However, now when I compile and execute the program, it executes but I get no feedback or errors so I'm not sure what is wrong or how to fix it.

I would test it with a different compiling program but I'm having a hard time getting any kind of c++ compiler installed.

I was wondering if anyone would be able to take a look and see what is going on. Let me know if the code is unclear.

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <iterator>
using namespace std;

class Person
{
   string first;
   string last;
   int age;
   
   public: 
     Person(string fn, string ln, int a);
     string getFname() { return first; }
     string getLname() { return last; }
     int getAge() {return age; }
     
     bool operator<(Person p2);
};

Person::Person(string fn, string ln, int a)
{
   first = fn;
   last = ln;
   age = a;
}

/**************************************
 * This part is to decide if a person is less than another
 * Person. Then return a boolean value.
 * 
 * ***********************************/


bool Person::operator<(Person p2){
    
    if(age < p2.getAge()){
        
        string first1 = first;
        string first2 = p2.getFname();
        
        string last1= last;
        string last2= p2.getLname();
        
        int i = 0;
        while(i < first1.length() && i < first2.length()){
            if(first1[i] < first2[i]){
                return true;
                i++;
            }
        }
        
        i = 0;
        while(i < last1.length() && i < last2.length()){
            if(last1[i] < last2[i]){
                return true;
                i++;
            }
        }
    }
    else
        return false;
}

/********************************
 * The program itself reads from an input.txt file and is to sort
 * the entries first by age from youngest to oldest and then alphabetically
 * by first name then last name. The program is then to print out the vector
 * containing the sorted Person entries.
 * 
 * *****************************/



int main()
{
    
    string fname;
    string lname;
    string tempAge;
    int age;
    
    ifstream myFile ("input.txt");
    vector<Person> myVector;
    vector<Person>::iterator myIt = myVector.begin();
    
    cout << "one";

    while(getline(myFile, fname)){
        getline(myFile, lname);
        getline(myFile, tempAge);
        age = atoi(tempAge.c_str());
        
        fname.erase(fname.length()-1); //Using an online compiler so getline grabs the \r character too
        lname.erase(lname.length()-1);
        
        Person p1 = Person(fname,lname,age); //Use this as a placeholder for the current Person being created.
        
        if(myVector.size() == 0){ //To add the first element to the vector.
            myVector.insert(myIt,p1);
        }
        
        else{ //Loop used to add the rest of the list to the vector.
            for(int i = 0; i < myVector.size(); i++){
                if(p1 < myVector[i]){
                    myVector.insert(myIt + i, p1);
                    myIt = myVector.begin();
                }
            }
        }

        //Supposed to go through the vector and print out each entry's information.
        for(int i = 0; i < myVector.size(); i++)
            cout << myVector[i].getFname() << " " << myVector[i].getLname() << ": " << myVector[i].getAge() << '\n';
    }
    
    
    myFile.close();
   


   
   return 0;
}


Sample text file:

John
Doe
24
Mary
Waters
32
Jill
Uphill
28
Jack
Felldown
16
Last edited on
It runs fine when I compile it (I didn't have any input text file) and outputs "one" (without quotes).
I threw in a cout << "one" to try and test it. I meant to take those out. It doesn't even print "one" out for me. The goal is to print out the whole vector of Persons though.
Last edited on
It now prints out (after adding that input file):

oneJoh Do: 24
Joh Do: 24
Joh Do: 24


Note: If you want a compiler and IDE go to http://www.codeblocks.org/downloads/26 and download the one which is written "codeblocks-13.12mingw-setup-TDM-GCC-481.exe". It is a nice IDE and includes a compiler.
Last edited on
+1 to Stormboy's suggestion.
Yeah. It must be the online compiler just not giving me any feedback. (Which I thought was the problem.) I know the output isn't correct right now but I need to get a IDE/compiler on my computer and I am having hell. I'm not good with installation paths and all the IDE's I download are super complicated to set up to me.
Follow this tutorial (after you have downloaded what I told you to):

http://www.cprogramming.com/code_blocks/
All that tutorial ended up giving me was

||=== Build: Debug in Person (compiler: GNU GCC Compiler) ===|
||Warning: .drectve `-aligncomm:"___hexdig_D2A",5' unrecognized|
:crt1.c||undefined reference to `__chkstk_ms'|
:glob.c||undefined reference to `__chkstk_ms'|
glob.c||undefined reference to `__chkstk_ms'|
glob.c||undefined reference to `__chkstk_ms'|
glob.c||undefined reference to `__chkstk_ms'|
glob.c||more undefined references to `__chkstk_ms' follow|
||=== Build failed: 6 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|

I'm totally new to all this IDE/compiler installation process. I began my coding career* using Java programming. It's a cinch to setup compared to this. I have to do this one in C++ though.
Last edited on
That error sounds very familiar...though I can't remember when I last saw it or what the problem actually was (or how I fixed it).

I would guess either an incompatible library (e.g. mixing libraries from different compilers or different versions of MinGW) or a messed-up installation.

Did you have MinGW previously installed on your system?
I did at home from troubleshooting. Currently at work where I received the error above. I am using netbeans now and seems to be going fine, but when I run the program with line 94:

age = atoi(tempAge.c_str());

IT NEVER FINISHES THE RUN. I let it run for 30 mins! I take it out with comments and let it establish it's own age and it runs... somewhat ok. Still having trouble with the vectors if anyone wants to try and solve those.

EDIT: Performing an atoi conversion OUTSIDE of the while loop seems to work but I really need it converting every age that comes in.

EDIT2: Found that the while loop is only iterating once. I have no idea why.
Last edited on
Topic archived. No new replies allowed.