2017-07-06 50 views
-3
#include <iostream> 
#include <cstdlib> 
#include <string> 
#include <conio.h> 
#include <fstream> 
using namespace std; 

int main() { 
    char input; 

    while (true) { 
    input = _getch(); 
    cout << "The input is: " << input << "\n"; 
    } 
    ifstream level1; 

    level1.open("level1.txt"); 

    string str[255]; 
    while (true) { 
    getline(level1 , str); 
    cout << str; 
    } 

    system("PAUSE"); 
} 

错误即时得到:函数getline错误,阅读每一行

没有没有重载函数“函数getline”的实例参数列表

什么即时试图做的是真正的每一行相匹配在文本文件中

+1

为什么你需要255个字符串的声明? – Rakete1111

+0

@ Rakete1111我不要,但它只是检查 – guy

+0

@Galik现在正在做它 – guy

回答

3

getline将字符串作为第二个参数,而不是字符串数组。

+0

好的谢谢!生病尝试,现在 – guy

1

您正在收到的错误说no instance of overloaded function "getline" matches the argument list

如果你看看getline原型你会看到istream& getline (istream& is, string& str);getline需要一个string&,不是string[255]&这是什么您是送它。

要么改变你的电话到getline(level1 , str[0]);或改变stringstring str;

+0

是啊,你上面的家伙帮助我了这一点,谢谢你,虽然顺便说一句,我如何检查文件的结局 – guy

+0

没有想到它了 – guy