Hey everyone,
I am just starting my C++ class here, and also new to Xcode programming. The following code can work in all other programming platform, but not Xcode. Can anyone help?
Here is my sampleInput.txt file:
frog freddie 60
duck donald 65
mouse minnie 95
mouse mickey 50
ghost casper 95
mouse abby 80
Any thought? Xcode bug??
thanks,
I am just starting my C++ class here, and also new to Xcode programming. The following code can work in all other programming platform, but not Xcode. Can anyone help?
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int const maxSize = 100;
int const maxLength = 30;
struct NameType {
int grade;
char lastName[maxLength];
char firstName[maxLength];
};
//function prototypes
bool readData( NameType[], int& );
int main ( ) {
NameType names[maxSize];
int size = 0;
bool success = readData(names, size);
cout << success << endl;
// Should print out the entries in the data file
cout << size << endl;
return 0;
}
bool readData( NameType names[], int& size ) {
ifstream infile("sampleInput.txt");
if( !infile ) {
cout << "File cannot open" << endl;
return false;
}
//can't pass the infile part test. only in Xcode...
while (size < maxSize && infile >> names[size].lastName
>> names[size].firstName
>> names[size].grade )
size++;
return true;
}
Here is my sampleInput.txt file:
frog freddie 60
duck donald 65
mouse minnie 95
mouse mickey 50
ghost casper 95
mouse abby 80
Any thought? Xcode bug??
thanks,