小编dch*_*han的帖子

如何在c ++中正确地将向量写入二进制文件?

感谢Mats Petersson关于如何将矢量复制到数组的解释,这看起来很有用.这是代码snipet:

#include <iostream>
#include <string.h>
#include <vector>
#include <fstream>

using namespace std;

class Student
  {
    private:
    char m_name[30];
    int m_score;

    public:
    Student()
      {

      }
    Student(const Student& copy)
      {
           m_score = copy.m_score;   //wonder why i can use this statment as
           strncpy(m_name, copy.m_name, 30); //declare it private
      }
      Student(const char name[], const int &score)
      :m_score(score)
      {
           strncpy(m_name, name, 30);
      }
      void print() const
      {
           cout.setf(ios::left);
           cout.width(20);
           cout << m_name << " " << m_score << endl;
      }
      };


      int main()
      { …
Run Code Online (Sandbox Code Playgroud)

c++ fstream

17
推荐指数
2
解决办法
4万
查看次数

标签 统计

c++ ×1

fstream ×1