2015-09-12 77 views
0

所以,我有这个程序,使用STL列表:如何填充数据结构列表?

#include "stdafx.h" 
#include <iostream> 
#include <list> 
#include <algorithm> 

using namespace std; 

const int numberOfStudents = 3; 

struct StudentInfo { 
    string name; 
    int grade; 



    }; 

void populateStudentRecords(list<StudentInfo>Students,list<int>::iterator iter){ 


} 



int _tmain(int argc, _TCHAR* argv[]) 
{ 
    list<StudentInfo>Records; 
    list<int>::iterator iter; 




    return 0; 
} 

我的问题是我怎么填充具有StudentInfo数据结构作为一种类型,其结构具有字符串名称和列表整数级?如何修改列表中每个结构实例的这两个变量?

+1

你有没有尝试过自己? – NathanOliver

+0

@NathanOliver我试过使用一个基本的for循环,如:for(int x = 0; x PythonCoder

回答

1
for (auto it = Records.begin(); it != Records.end(); ++it) { 
    it->name = ... 
    it->grade = ... 
}