...ifstream myfile("all_good/2.txt");
if (myfile.is_open())
while (getline(myfile, line))
{
cout << line << '\n';
}
myfile.close();
}
else
{
cout << "Unable to open file";
}
}
ifstream myfile("all_good/3.txt");
if (myfile.is_open())
{
while (getline(myfile, line))
{
cout << line << '\n';
}
myfile.close();
}
else
{
cout << "Unable to open file";
}
}...
我如何实现这种格式。这是来自两个不同文本文件的两种格式,因此,如何在同一行中水平地按此顺序打印文件?
-2 -------- 2- -3 -------- 3-
-2 -------- 2- -3 -------- 3-
对两个文件进行锁定操作。首先打开两个文件,然后从两个文件中读取,然后以锁定步骤打印出行。像这样的东西:
ifstream myfile2("all_good/2.txt");
ifstream myfile3("all_good/3.txt");
if (myfile2.is_open() && myfile3.is_open())
{
while (getline(myfile2, line2) && getline(myfile3, line3))
{
cout << line2 << line3 << '\n';
}
myfile2.close();
myfile3.close();
}
else
{
cout << "Unable to open files";
}