字符串与文件数据的比较
Comparison of string with the File data
我目前陷入了一个非常简单的问题,这段代码是我的程序的一部分,它从用户获取数据,然后从文件(包含电影和演员的名称)中读取数据,并将其与输入进行比较,但它给出了错误的结果。这是我的代码
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
string name;
getline(cin, name);
string compare;
ifstream myfile;
myfile.open("movie.txt");
bool found = false;
if (myfile.is_open())
{
while (getline(myfile, compare))
{
if (compare == name)
{
cout << "record found" << endl;
found = true;
}
}
myfile.close();
}
if (found)
cout << "not found" << endl;
}
任何关于这方面的帮助将是感激的。由于
对于调试,您可以从这里在compare
和name
上使用string_to_hex
相关文章:
- 将字符串与文件上的数据进行比较
- 如何在 c++ 中比较 2 个链表并将匹配的数据放入另一个链表中
- 将收到的 usart uint8_t* 数据与常量字符串进行比较
- 比较付款数据
- 将constexpr字节数组与缓冲区的一部分(指向数据的指针)进行比较
- 任何方法都可以在C++中比较数据结构中的许多方法
- C++,"由于数据类型范围有限,比较总是正确的"
- 比较存储在 std::string 中的数据中的字节数
- C++ - 比较模板和类之间的数据类型
- 将此类数据作为字符串进行比较时出现问题
- 将当前多边形数据单元与下一个多边形单元格 - VTK 进行比较
- 比较 JSON::Value 变量中的数据,然后更新到文件
- 如何使用自定义比较器初始化类数据成员,该成员是 std::set
- 将 ProcessEntry32.szExeFile 与用户输入的数据进行比较时,C++ _wcsicmp代码未编译
- 可以比较不同数据类型 c++ 的模板函数
- 比较推送数据(100 万个数字)在 std::vector 中预先调整大小和没有
- 从数据文件中读取每2个字节,并在向量中进行比较
- 比较堆栈数据结构 c++
- C++:比较数据文件中的点集
- 整数类和分数类的添加和比较数据的操作符重载