读取名称列表到数组中

sir*_*isp 3 c++

我刚刚意识到我从来没有学会从文件中读取字符串,所以我做了一些搞乱来解决它,但我的编译器有问题.

对于我的编程类,我使用visual c ++ 2010,因为它是必需的,它没有给我太多问题,所以我没有切换到任何其他.

无论如何,我的代码和我的问题.它基本上应该从文件中读取全名并将它们存储在一个数组中.

#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++;
 }

}
Run Code Online (Sandbox Code Playgroud)

在我的while循环中,我收到了:错误:没有运算符"<="匹配这些操作数.

我和我使用的任何其他运算符都得到了同样的东西.有帮助吗?

Mys*_*ial 5

你想要这个:

while (sub < 100)
Run Code Online (Sandbox Code Playgroud)

最初,您将字符串与整数字面值进行比较.你显然不能这样做.

请注意,我也改变了<=,<否则,你将超越阵列.