在C++中仅获取类似的数据。向量
我正在尝试从具有与图像相似的最后值的.txt文件中获取所有数据。
例如,我经过并创建一个向量,其中仅保存在文件中,只有具有相同最后一个值的行“ 1565514F”,然后当我找到另一个最终值“ 1678721f”时,我创建了另一个文件和因此,在无限的情况下,第一个文件将具有“ 1565514f.txt”的名称,并且可以保存在同一或另一个向量中,像
1001;2021-03-01;False;0;0;1565514F
1001;2021-03-02;False;0;0;1565514F
1002;2021-03-03;False;0;0;1565514F
1002;2021-03-04;False;0;0;1565514F
1003;2021-03-05;False;0;0;1565514F
1003;2021-03-06;False;0;0;1565514F
1004;2021-03-07;False;0;0;1565514F
另一个文件一样的数据将称为“ 1678721f.txt”,并且将类似的数据称为
1006;2021-03-03;False;0;0;1678721F
1006;2021-03-04;False;0;0;1678721F
1001;2021-03-05;False;0;0;1678721F
1001;2021-03-06;False;0;0;1678721F
1004;2021-03-07;False;0;0;1678721F
1004;2021-03-08;False;0;0;1678721F
1003;2021-03-09;False;0;0;1678721F
i code the code the code。已经完成的是以下
// read file
ifstream archivoPlanificacion;
archivoPlanificacion.open("entrada/Planificacion.txt");
string linea;
vector<string> planificacionVector;
while(getline(archivoPlanificacion, linea))
{
planificacionVector.push_back(linea);
}
archivoPlanificacion.close();
for (int i = 0; i < planificacionVector.size(); i++) {
vector<string> planificacionSplitted = splits(planificacionVector[i], ';');
string planificacionFecha = planificacionSplitted[1];
string planificacionRut = planificacionSplitted[5];
cout << "Planificacion Rut: " << planificacionRut << endl;
if (planificacionRut == planificacionSplitted[5]){
vector<string> soloRutMismoUser;
soloRutMismoUser.push_back(planificacionSplitted[5]);
//imprimir vector soloRutMismoUser
for (int i = 0; i < soloRutMismoUser.size(); i++) {
cout << "soloRutMismoUser: " << soloRutMismoUser[i] << endl;
}
} else {
cout << "nuevo rut" << endl;
string aux = planificacionRut;
//crear archivo de salida
}
cout << "Planificacion Fechas: " << planificacionFecha << endl;
}
我不知道是否有更好的方法,但是我问,因为我筑巢了很多,我很感激任何帮助,我仍然无法将数据与“如果”分开,谢谢
I'm trying to get all the data from a .txt file that have a similar last value, as in the image.
for example, I go through and create a vector where I save in a file only the lines that have the same last value "1565514F" then when I find a different final value "1678721F" I create another file and so on infinitely, the first file would have the name "1565514F.txt" and would save in the same, or in another vector, data like
1001;2021-03-01;False;0;0;1565514F
1001;2021-03-02;False;0;0;1565514F
1002;2021-03-03;False;0;0;1565514F
1002;2021-03-04;False;0;0;1565514F
1003;2021-03-05;False;0;0;1565514F
1003;2021-03-06;False;0;0;1565514F
1004;2021-03-07;False;0;0;1565514F
another file would be called "1678721F.txt" and would have data like this
1006;2021-03-03;False;0;0;1678721F
1006;2021-03-04;False;0;0;1678721F
1001;2021-03-05;False;0;0;1678721F
1001;2021-03-06;False;0;0;1678721F
1004;2021-03-07;False;0;0;1678721F
1004;2021-03-08;False;0;0;1678721F
1003;2021-03-09;False;0;0;1678721F
the code that I have done is the following
// read file
ifstream archivoPlanificacion;
archivoPlanificacion.open("entrada/Planificacion.txt");
string linea;
vector<string> planificacionVector;
while(getline(archivoPlanificacion, linea))
{
planificacionVector.push_back(linea);
}
archivoPlanificacion.close();
for (int i = 0; i < planificacionVector.size(); i++) {
vector<string> planificacionSplitted = splits(planificacionVector[i], ';');
string planificacionFecha = planificacionSplitted[1];
string planificacionRut = planificacionSplitted[5];
cout << "Planificacion Rut: " << planificacionRut << endl;
if (planificacionRut == planificacionSplitted[5]){
vector<string> soloRutMismoUser;
soloRutMismoUser.push_back(planificacionSplitted[5]);
//imprimir vector soloRutMismoUser
for (int i = 0; i < soloRutMismoUser.size(); i++) {
cout << "soloRutMismoUser: " << soloRutMismoUser[i] << endl;
}
} else {
cout << "nuevo rut" << endl;
string aux = planificacionRut;
//crear archivo de salida
}
cout << "Planificacion Fechas: " << planificacionFecha << endl;
}
I don't know if there is a better way, but I asked because I was nesting many for, I would appreciate any help, I still can't separate the data with the "if", thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
修改您的循环
我尚未对此进行测试,因为我没有数据结构或文件。
Modifying your loop
I have not tested any of this because I don't have the data structures or the file.