c++ - 如何从文件中获取数据并添加到构造函数
问题描述
我正在尝试从此文件中获取数据并将其添加到我的构造函数中。我做错了什么,我明白,但我需要更正。具体来说,在我的获取等级函数中,如何将类对象设置为文件中的数据:
文件数据为:
Mary Smith 10 5 8 10 6 2 10
Ken Lewis 5 3 2 10 8 9 10
我的代码:
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
void get_grade();
//void compute_grade();
class Student
{
public :
string firstname;
string lastname;
int lab1;
int lab2;
int lab3;
int lab4;
int lab5;
int lab6;
int lab7;
Student(string a, string b, int c, int d, int e, int f, int g, int h){
firstname = a;
lastname = b;
lab1 = c;
lab2 = d;
lab3 = e;
lab4 = f;
lab5 = g;
lab7 = h;
}
};
int main()
{
get_grade();
}
void get_grade()
{
//Student stud2();
ifstream myfile;
myfile.open("infile.txt");
myfile >> stud1.firstname;
cout << stud1.firstname;
}
解决方案
推荐阅读
- javascript - 为什么道具/动作没有第一次通过?
- c# - Signalrhub 中的 asp.net core 3.1 服务生命周期和 Observable sobscriptions
- powershell - 使用databricks在adls gen2中导入表数据并保存为json文档
- sequelize.js - 用今天的日期续集 where 语句
- node.js - 使用节点导出大型数据集的内存问题
- c# - 单例继承和装饰器模式
- sql - 从 MS Access 转换到 SQL Server 时转换多个 IIf
- javascript - React/Gatsby 组件与 MDX 文件中的组件交互(提升状态)
- javascript - 在 Angular 组件和非 Angular 组件之间进行通信:从来自回调的可观察对象返回数据
- html - 在 VScode 中按 Enter 选择建议