unsigned short m_bytesCount = 0;
for (size_t i = 0; i < 3; i++)
{
for (size_t k = 0; k < 6; ++k)
{
if (vec[i2++] == 1)
m_bytesCount |= 1 << i2;
}
binaryFile.write((char *)&m_bytesCount, sizeof m_bytesCount);
}
return 0;
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <iterator>
int main()
{
int i2 = 0;
std::ofstream binaryFile("file.dat", std::ios::out | std::ios::binary);
std::fstream input2("input2.txt");
std::vector<short> vec;
std::copy(std::istream_iterator<int>(input2), std::istream_iterator<int>(), std::back_inserter(vec));
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>(std::cout, " "));
unsigned short m_bytesCount = 0;
for (size_t i = 0; i < 3; i++)
{
for (size_t k = 1; k < 6; ++k)
{
if (vec[++i2] == 1)
m_bytesCount |= 1 << i2;
}
binaryFile.write((char *)&m_bytesCount, sizeof m_bytesCount);
}
return 0;
}
int main()
{
std::fstream input("input.txt");
std::fstream input2("input2.txt");
std::vector<short> vec; // значения из файла input.txt
std::copy(std::istream_iterator<int>(input), std::istream_iterator<int>(), std::back_inserter(vec));
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>(std::cout, " "));
std::vector<int> vec2; // значения из файла input2.txt
std::copy(std::istream_iterator<int>(input2), std::istream_iterator<int>(), std::back_inserter(vec2));
std::copy(vec2.begin(), vec2.end(), std::ostream_iterator<int>(std::cout, " "));
std::ofstream fout("data.dat", std::ios::out | std::ios::binary);
const size_t columnCount = 6;
for (size_t i = 0; i < vec.size(); i += columnCount)
{
int index = i / columnCount + 1;
fout.write((char *)&index, sizeof(int));
for (size_t j = 0; j < columnCount; j++)
{
fout.write((char*)&vec[i + j], sizeof(short));
}
// Запись значений второго файла
unsigned short m_bytesCount = 0; // запись 1й строки в 2 байта
for (size_t k = 0; k < columnCount; k++)
{
if (vec2[i+k] == 1)
m_bytesCount |= 1 << i+k;
}
fout.write((char *)&m_bytesCount, sizeof m_bytesCount);
}
fout.close();
return 0;
class InfAnalogChanel
{
public:
int id;
std::string chanell_id;
std::string ph;
std::string ccmb;
std::string UU;
double a;
double b;
double skew;
double min;
double max;
double Primery;
double Secondary;
std::string SP;
};
void writesecondline (std::ostream &file, InfAnalogChanel const &iac);
void writesecondline(std::ostream &file, InfAnalogChanel const &iac){
ofstream file("fileConfiguration.cfg");
}
InfAnalogChanel a = {1,"ток ф А",,,"A",1.290489E-01,0,0,-32767,32767,3000.00000000,1.00000000,"P"};
InfAnalogChanel b = {2,"ток В",,,"A",5.139708E-02,0,0,-32767,32767,3000.00000000,1.00000000,"P"};
ofstream file("fileConfiguration.cfg");
writesecondline(file, a);
writesecondline(file, b);
class InfAnalogChanel
{
public:
int id;
std::string chanell_id;
std::string ph;
std::string ccmb;
std::string UU;
double a;
double b;
double skew;
double min;
double max;
double Primery;
double Secondary;
std::string SP;
};
vector<InfAnalogChanel> s;
void writesecondline (s[i].id, s[i].chanell_id, s[i].ph, s[i].ccmb, s[i].UU, s[i].a, s[i].b,s[i].skew,
s[i].min,s[i].max,s[i].Primery,s[i].Secondary,s[i].SP);
void writesecondline (s[i].id, s[i].chanell_id, s[i].ph, s[i].ccmb,
s[i].UU, s[i].a, s[i].b,s[i].skew,
s[i].min,s[i].max,s[i].Primery,s[i].Secondary,s[i].SP){
ofstream file("fileConfiguration.cfg");
for(size_t i=0;i<s.size();++i)
file<<s[i].id<<","<<s[i].chanell_id<<","<<s[i].ph<<","<<s[i].ccmb<<","<<s[i].UU<<","<<s[i].a<<","<<s[i].b<<","<<s[i].skew<<
","<<s[i].min<<","<<s[i].max<<","<<s[i].Primery<<","<<s[i].Secondary<<","<<s[i].SP<<"\n";}
InfAnalogChanel a;
InfAnalogChanel b;
a.id=1;
a.chanell_id="ток ф А";
a.ph="";
a.ccmb="";
a.UU="A";
a.a=1.290489E-01;
a.b=0;
a.skew=0;
a.min=-32767;
a.max=32767;
a.Primery=3000.00000000;
a.Secondary=1.00000000;
a.SP="P";
b.id=2;
b.chanell_id="ток В";
b.ph="";
b.ccmb="";
b.UU="A";
b.a=5.139708E-02;
b.b=0;
b.skew=0;
b.min=-32767;
b.max=32767;
b.Primery=3000.00000000;
b.Secondary=1.00000000;
b.SP="P";
writesecondline(s[i].id, s[i].chanell_id, s[i].ph, s[i].ccmb, s[i].UU, s[i].a, s[i].b,s[i].skew,
s[i].min,s[i].max,s[i].Primery,s[i].Secondary,s[i].SP);
input2.txt
1 1 1 0 1 1 1 0 0 0 1 1 0 0 0 0 1 1
В итоге исключение