Reading text files in Xcode

I have a program that needs to be able to have a file name inputted and from that input open a txt file to be read from. But I can't seem to get it to open them. I have the text files and all the cpp files and all the header files in the same folder.

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
 if (ffile.is_open())
            {
                ffile.close();
            }
            cout << "Please enter the name of a file to be read" << endl;
            cin >> filename;
            ffile.open (filename);
            if (ffile.is_open())
            {
                while(!ffile.eof())
                {
                    
                    ffile >> type;
                    
                    if (type == "Residential")
                    {
                        ffile >> rent_or_own >> price >> occupation;
                        getline (ffile, address);
                        
                        if(ffile.fail()||price < 0)
                        {
                            cout << "Error, ignoring bad input " << endl;
                            ffile.clear();
                            ffile.ignore(1000, '\n');
                        }
                        else
                        {
                            Residential* r = new Residential(rent_or_own, price, occupation, address);
                            properties.push_back(r);
                        }
                        
                    }
                    else if (type == "Commercial")
                    {
                        ffile >> rent_or_own >> price >> tax_eligibility >> tax_discount;
                        getline (ffile, address);
                        
                        if(ffile.fail()||price < 0)
                        {
                            cout << "Error, ignoring bad input " << endl;
                            ffile.clear();
                            ffile.ignore(1000, '\n');
                        }
                        else
                        {
                            Commercial* c = new Commercial(rent_or_own, price, tax_discount, tax_eligibility, address);
                            properties.push_back(c);
                        }
                    }
                }
            }
            else
            {
                cout << "Error, bad file name" << endl;
            }
  
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/general/204722/
Topic archived. No new replies allowed.