是否有C++算法来计算多个数字的最小公倍数,如lcm(3,6,12)或lcm(5,7,9,12)?
我有以下数据结构作为名为"任务"的类:
private:
string name;
int computation_time;
int period;
Run Code Online (Sandbox Code Playgroud)
此外,我有一个ASCII文件与此内容:
A 3 10
B 2 12
C 1 11
Run Code Online (Sandbox Code Playgroud)
name = A,computation_time = 3,period = 10等等......
现在我想在文件中读取,创建Task-object并将其推回到向量中:
void read_in_task_list_and_create_tasks(const string &filename, vector<Task> ¤t_tasks)
{
ifstream in_file;
in_file.open(filename.c_str());
string tmp_name;
int tmp_computation_time;
int tmp_period;
while(!in_file.eof())
{
in_file >> tmp_name;
in_file >> tmp_computation_time;
in_file >> tmp_period;
// Task tmp_task(tmp_name, tmp_computation_time, tmp_period);
// current_tasks.push_back(tmp_task);
current_tasks.push_back(Task(tmp_name, tmp_computation_time, tmp_period));
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我查看current_tasks向量时,它有元素,但它们的值与我的in_file值不匹配.观看已注释的线条.tmp_task对象是完全正确的,但如果它被推回,它就会丢失它的值,就像上面描述的那样.
这可能是Task-class中的Copy-Constructor问题,因为std :: vector正在管理内存分配吗?
我在Linux x86上使用带有g ++编译器的netbeans.
谢谢