【发布时间】:2018-03-15 10:59:24
【问题描述】:
我正在为我的数据库进行注册,但编译器总是对我说:
没有匹配函数调用'std::basic_ifstream::getline(std::__cxx11::string&, int&)' getText.getline(pass_password, data_count_password);
我不明白我的代码中的错误在哪里..谁能帮助我?
代码:
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
bool is_user = false,startDatabase = false;
string file_text;
string username;
string password;
string repeat_password;
bool isCorrect = false;
int main(int argc, char const *argv[])
{
ofstream setText("user_data.txt");
ifstream getText("user_data.txt");
getText.getline(file_text,10);
if(file_text == ""){
while(!isCorrect){
cout << "For using our dataBase, please enter data for
privacy \nUsername : ";
cin >> username;
cout << "Password : ";
cin >> password;
cout << "Repeat password : ";
cin >> repeat_password;
if(password == repeat_password){
isCorrect = true;
}else{
cout << "Please, repeat and enter identistic passwords!";
isCorrect = false;
}
}
setText << username << password;
}else{
int data_count_username = username.length();
int data_count_password = password.length();
string pass_password;
string pass_username;
cout << "Please enter your data " << endl << "Username : ";
cin >> username;
cout << "Password : ";
cin >> password;
getText.getline(pass_username,data_count_username);
getText.getline(pass_password, data_count_password);
if(pass_username == username && pass_password == password){
startDatabase = true;
}
}
setText.close();
getText.close();
return 0;
}
【问题讨论】:
-
我该如何解决? - 只需将字符串更改为 char 数组?
-
en.cppreference.com/w/cpp/io/basic_istream/getline 显然它接受 char* 而不是字符串使用 file_text.c_str()
-
页面底部有一个示例
-
所以.....问题是字符?
-
是的,它必须是 char*
标签: c++ file registration ifstream ostream