Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Hỏi về list trong c++

8 năm trước 2.024 lượt xem 2 bình luận 8 năm trước

em mới học về file và list khi viết code thì bị lổi 

 Error C2039 'tu': is not a member of 'std::_List_iterator<std::_List_val<std::_List_simple_types<PhanSo>>>

 

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
thangliudiu đã bình luận 8 năm trước

Bạn gì ấy đọc chơi

P/S ai đẹp trai/ đẹp gái đọc xong chỉ tui làm con trỏ. đưa thẳng list<> vào trong hàm được không

#include "stdafx.h";
#include<fstream>
#include<iostream>
#include <list>

using namespace std;

#pragma region question
class   PhanSo
{
public: PhanSo()
{
    tu = 0;
    mau = 1;
}
public: int tu;
        int mau;
};
list<PhanSo> DocMangPS(char *filename);
void GhiMangPS(char *filename, list<PhanSo> a);

void main()
{
    list<PhanSo> a  = DocMangPS("input.txt");
    GhiMangPS("output.txt", a);
    system("pause");
}
list<PhanSo> DocMangPS(char *filename)
{
    list<PhanSo> b;
    ifstream fin;
    fin.open(filename);
    if (fin.is_open() == false)
    {
        cout << "Ko the doc file " << filename << endl;
    }
    else
    {
        cout << "Da mo dc file " << filename << endl;
        int n;
    
        fin >> n;
        for (int i = 0; i<n; i++)
        {
            PhanSo p;
            fin >> p.tu;
            fin >> p.mau;
            b.push_back(p);
        }
        fin.close();
    }
    return b;
}
void GhiMangPS(char *filename, list<PhanSo> a)
{
    ofstream fout;
    fout.open(filename);
    if (fout.is_open() == false)
    {
        cout << "Ko the ghi file " << filename << endl;
    }
    else
    {
        cout << "bat dau ghi file " << filename << endl;
        fout << a.size() << endl;
        for (list<PhanSo>::iterator it = a.begin(); it != a.end(); it++)
        {
            PhanSo p = *it;
            fout << p.tu << endl;
            fout << p.mau << endl;
        }
        fout.close();
    }
}

#pragma endregion

 

Câu hỏi mới nhất