gpt4 book ai didi

C++ ifstream is_open() 失败

转载 作者:太空宇宙 更新时间:2023-11-04 15:34:26 36 4
gpt4 key购买 nike

<分区>

为什么我的 is_open() 总是失败并进入显示错误消息的 else 语句?

我的另一种方法与此类似但有效。

#include <iostream>
#include <fstream>
using namespace std;

int main() {
string userName;

cout << "Please login to your account here!" << endl;
cout << "Username: ";
cin >> userName;

ifstream openSalt;
openSalt.open("salt.txt"); //open the file

if(openSalt.is_open()) //if file is open
{
string temp;

while (getline(openSalt,temp))
{
//gets content
//if user exists, login
//else, exit
}
openSalt.close();
}
else
{
cout << "Error opening file!" << endl;
exit(1);
}
return 0;
}

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com