从.txt文件找到并验证C 的特定用户ID
Locating and validating a specific user ID from .txt file for c++
我不确定如何读取有关读取文本文件的特定信息点。我要做的是。
- 从其输入(CIN>>用户ID)获取用户ID
- 程序检查ID是否存在于数据库中(读取.txt文件)
- 如果存在ID,请继续进行下一个部分
-
其他,cout错误消息
//Example text from the file:
12345678 23456789 34567890 45678901 etc. etc. etc.
在这里,如果用户输入" 12345678",我想了解如何允许C 在.txt文件中专门扫描12345678。因此,生成" 识别"消息。"消息。还是有人可以慷慨地将我引导到适当的链接?
您将要使用std :: string :: find。
示例:
if (fullString.find(partOfString) != std::string::npos) {
std::cout << "found!" << endl;
}
因此,在您的示例中,您所使用的文本文档的行将是fullString
,输入的用户ID将是零件。您也可以直接与
if (userString == lineFromFile)
{
//do something
}
"在.txt文件中专门扫描123456" - 您不能。您拥有的是文本文件,而不是数据库。如果您的文件很大,我认为解决方案将是使用数据库(例如SQLITE),并让它为您生成索引。然后,您可以查询数据库中的任何匹配XYZ的用户ID。
假设您知道如何使用fstream and whats打开文件,则可以做一些段循环。
ifstream yourFile;
int userID, wantedID;
bool found = false;
//open file
while(yourFile >> userID && found == false){ //this says while there is numbers that can be put into UIN, do this. This way it won't keep trying after it has run out of numbers, and will also stop if/when it is found, whichever comes first.
if(UserID == wantedID){
found = true;
}
}
因此,这将允许的操作是搜索整个文件以查找ID,而当发现它时停止搜索。然后,您可以按照自己的意愿来完成您的意愿,尽管您也很可能仍然希望在使用UserId时检查发现的布尔值,以防目前没有找到并耗尽数字。
相关文章:
- C++如何通过用户输入删除列表元素
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何使用用户输入在C++中正确填充2D数组
- C++MySQL C api用户输入行
- 使用用户定义函数的字符串反转
- 用户定义函数中的指针和输入
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- 如何只允许用户输入正整数
- C++如何计算用户输入的数字中的偶数位数
- 通过for循环使用用户输入填充列表
- 使用 C++ 和 cURL,如何通过需要用户 ID 和密码的 url 获取图像
- 使用 LDAP - 本机 API 中的页面控件获取活动目录组中的所有用户 ID
- 从.txt文件找到并验证C 的特定用户ID
- 使用 C 在 Linux 中设置用户的补充组 ID
- 需要调试"在')'令牌之前预期的非限定id",第一次使用c ++的用户
- QFile和QTextStream帮助(为具有用户名、密码和名称的用户编写ID)
- QVariant用户类型()id
- 仅使用一个用户id和密码访问数据库
- Windows登录的用户唯一ID
- wxID_ANY, wxNewId()和用户给出的id