如何在 c++ 中比较两个文本文件
How do i compare two text files in c++
好吧,我到处搜索过,无法得到它,所以..
- 我正在做一个图书馆系统,图书馆员输入他的用户名,程序检查他是否是图书馆员之一 我
- 卡在比较部分,我尝试使用 getline 但它给了我一个错误,尝试gets_s并使用 char 数组而不是字符串,但仍然不起作用
请帮助我做什么
using namespace std;
#include <iostream>
#include <string>
#include <fstream>
int main()
{
//opening files
ifstream readUsername;
ofstream enterUsername;
//variables
string existUsername;
string enteredUsername;
//reading files
readUsername.open("librarian usernames.txt");
if (readUsername.fail())
{
cout << "can't open file" << endl;
}
enterUsername.open("entered librarian username.txt");
if (enterUsername.fail())
{
cout << "can't open file" << endl;
}
while(!readUsername.eof)
{
readUsername >> existUsername;
}
enterUsername << enteredUsername;
readUsername.close();
enterUsername.close();
enterUsername.clear();
system("pause");
return 0;
}
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream infile;
infile.open("listOfWords.txt"); //open file
for(string listOfWords; getline(infile, listOfWords, '.'); ) //read sentences including
//spaces
cout<<listOfWords; //this displays
return 0;
}
这将向您展示如何输出文本,因此您应该将两个文件保存到一个变量中,然后比较变量。
相关文章:
- 在 c++ 中从文本文件中读取两个十六进制值
- 如何在c ++中以一行(水平)打印两个文件的数据?如给定的.这两种形式来自两个不同的文本文件
- 如何在 c++ 中比较两个文本文件
- 正则表达式 获取两个换行符之间的文本
- C ++将文本存储在数组的不同索引中,并带有一两个
- C++比较两个文本文件的上下文
- 两个循环内的多个文本文件
- 在文本中的两个非唯一字符串之间获取子弦
- 将两个文本文件合并为一个会给出不同的输出
- 合并两个文本文件会产生奇怪的结果
- 使用两个文本文件构建链表
- 如何在两个文本文件中计算不同的数据包编号
- 读入两个文本文件,然后将它们组合在一起
- 用C++将两个文本文件合并到第三个文本文件中
- 库合并两个文本文件
- 合并两个文本文件排序
- 在两个文本文件中找到最常用的单词
- 在两个文本文件中搜索单词
- libgit2 - 两个文本斑点上的差异
- 添加两个文本框浮动值,需要在第三个文本框中显示