使用外部文件中的变量进行视觉C++
visual C++ using a variable from an external file
我是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 usernamen";
cin >> user;
cout << "Make your passwordn";
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
}
相关文章:
- 视觉studo 2019中的漫画和静态/动态绑定
- 如何改变c++应用程序的视觉效果
- 视觉工作室项目.提取源文件夹名称
- 为什么我在尝试模板时遇到视觉工作室C++错误
- 视觉工作室 2017;启用 /permissive 时,类型 "const wchar_t *" 的参数与类型 "PWSTR" 的参数不兼容
- 视觉我希望一个函数在另一个函数C++中进行计算
- 视觉 如何循环访问C++中遵循类似格式的多个.txt文件?
- remove(str.begin(), str.end(), );无法正常工作(我正在使用视觉工作室 2012)
- 背包问题,视觉工作室问题
- 如何在视觉c ++项目中添加箭头键作为修饰键Microsoft
- 如果变量数据包含大于 vector 所有元素的整数,则仅在视觉工作室上接收"矢量下标超出范围"?
- 视觉C++未按所需顺序打印
- 视觉C++使用 map 来比较字符串中的每个单词
- C++11 中好友模板类的视觉C++错误
- 迭代器跳闸视觉C++ 2017 断言
- 视觉C++联盟,垃圾价值
- 无法安装由视觉C++制作的apk
- C++ 调试断言失败 - 矢量下标超出视觉工作室的范围
- 视觉C++:在 DLL 加载期间,全局变量初始化顺序是否具有确定性?
- 使用外部文件中的变量进行视觉C++