我是 C++ 的新手,但到目前为止我喜欢它。
最近我一直在制作越来越好的控制台应用程序,就像登录一样,但是你会在同一个会话中提供密码字符串和用户名字符串。
我试图让你打开应用程序并检查某个文件,如果它不存在,它将创建它并要求你给它一个值。我希望这能让我拥有一个用户创建的密码和已经设置的用户名,而不是几个已经有值但不是用户创建的字符串。
我的最佳版本的代码(它不是很好的代码)也不会只发布他们创建通行证的部分。
#include "stdafx.h"
#include "iostream"
#include "string"
#include "windows.h"
using namespace std;
int main() {
string user;
string pass;
string entry;
cout << "Make your username\n";
cin >> user;
cout << "Make your password\n";
cin >> pass;
return 0;
}
这段代码还有很多(大约 80 行),但我觉得不需要大部分信息。
使用std::ifstream
管理文件
std::ifstream f("path_to_file");
if (f.fail()) {
// we can't us the file (doesn't exist, incorrect permissions, etc.)
// instead, ask the user to enter their credentials
} else {
// read the file and extract necessary information
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句