Mình có đoạn code như này:
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable::4996)
#include “ThongTin.h”
int main()
{
_setmode(_fileno(stdin), _O_U16TEXT);
_setmode(_fileno(stdout), _O_U16TEXT);
_wfreopen(L"Input.txt",L"rt" , stdin);
const std::locale empty_locale = std::locale::empty();
typedef std::codecvt_utf8<wchar_t> converter_type;
const converter_type* converter = new converter_type;
const std::locale utf8_locale = std::locale(empty_locale, converter);
std::wifstream stream(L"Input.txt");
stream.imbue(utf8_locale);
wcin.imbue(utf8_locale);
wcout.imbue(utf8_locale);
CThongTin a;
[//a.taoStream](https://a.taostream/)(“Input.txt”, “Output.txt”);
a.nhap();
_wfreopen(L"Output.txt", L"wt", stdout);
a.xuatPhongCoNhieuNguoi();
return 0;
}
#include “ThongTin.h”
void CThongTin::nhap()
{
wstring temp;
getline(wcin, temp);
this->maPhong = temp.substr(0, 3);
this->hoTen = temp.substr(3, temp.length());
this->xuLiKhoangTrang();
}
vector<vector> CThongTin::nhapLienTuc()
{
vector<vector> a(1, vector(1,*this));
while (!wcin.eof())
{
CThongTin b;
b.nhap();
int flag = 0;
for (int i = 0; i < a.size(); i++)
{
if (b.maPhong.compare(a[i][0].maPhong) == 0)
{
a[i].push_back(b);
flag = 1;
}
}
if (flag == 0)
{
a.push_back(vector(1, b));
}
}
return a;
}
Thế nhưng khi thực hiện if (b.maPhong.compare(a[i][0].maPhong) == 0)
thì mình lại thấy có vấn đề như này.
2 dãy string giống nhau là cùng “P1” nhưng lại không bằng nhau.
Mình nhận thấy do từ P1 này nằm đầu tiên trong file nên có vấn đề j đó. Tại vì mình thay thế cho một chuỗi khác đứng đầu file thì 2 dãy P1 này bằng nhau. Mong mọi người chỉ giúp!