我的 Visual c++ 托管单元测试项目未读取输入文件

My Visual c++ managed Unit test Project not Reading a input file

本文关键字:读取 输入 文件 项目 单元测试 Visual c++ 我的      更新时间:2023-10-16

我正在使用VisualStudio 2015,正在处理c ++托管的单元测试项目,我通过文本文件给出输入值,但它不谈论文件中的值

我的代码在这里

    struct employee
     {
       char name[20];
       char department[25];
       double salary;
      }
  [TestMethod]
  void Employee_Test()
  {
VEMPLOYEE Expectedemployee; //This is class 
employee emp_Test;
infile.open("Output_Expected.txt",ios::in);
        if (!infile)
            exit(1);

        for(int i=0;i<3;i++)
        {
            infile >> emp_Test.name >> emp_Test.department >> emp_Test.salary;
            Expectedemployee.push_back(emp_Test);
        }
        infile.close();
       }

但是在我的测试代码中没有读取文件值,预期员工容器显示为空,

我的输入文件是

    Robin  IT 25000
    Nikson IT 20000
    Bob    IT 20000

通过对上面的代码进行一些小的修复,我在我的机器上成功地运行了代码(win10/gcc(。 所以,我想问题很可能与您的类VEMPLOYEE有关,并且可能特定于push_back()成员函数。

我使用VEMPLOYEE作为测试目的的vector,我希望您将class实现为像容器一样工作,但我在"VEMPLOYEE Expectemployee"行中看不到任何大小/类型相关信息;

所以,至少你的文件例程是好的。 检查您的class .