I’ve just realized that I’ve never learned to read strings from file, so I did a little messing around to figure it out, but I’m having a problem with my compiler.
For my programming class I use visual c++ 2010 because it is required and it hasn’t given me much problem so I haven’t switched to any other.
Anyways heres my code and my problem.
It is basically supposed to read in full names from a file and store them in an array.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
const int maxsize = 100;
string friendArray[maxsize];
ifstream friends;
friends.open("myFriends.dat");
int sub = 0;
while (friendArray[sub] <= 100)
{
getline(friends, friendArray[sub]);
sub++;
}
}
in my while loop, I am recieving: error: no operator “<=” matches these operands.
I’m getting the same thing with any other operators I use also.
Any help?
You want this instead:
Originally, you were comparing a string to an integer literal. You obviously can’t do that.
Note that I also changed the
<=to<otherwise, you’ll be overrunning the array.