я пишу указатель на символ в файл, но моя программа всегда падает на имя, когда я это сделать, и я не в состоянии понять, почемуне может записать указатель файла полукокса
#include <iostream>
#include <iomanip>
#include <string>
#include "AmaProduct.h"
using namespace std;
namespace sict{
AmaProduct::AmaProduct(char file){
fileTag_ = file;
}
const char* AmaProduct::unit()const{
return unit_;
}
void AmaProduct::unit(const char* value){
for (int i = 0; i != 9; i++){
unit_[i] = value[i];
}
unit_[11] = 0;
}
fstream& AmaProduct::store(fstream& file, bool addNewLine)const{
file.open("file.txt");
if (file.is_open()){
file << fileTag_ << "," << sku() << ",";
file<< name() << ",";//here
file<< price() << "," << taxed() << "," << quantity() << "," << unit_ << "," << qtyNeeded();
if (addNewLine){
file << endl;
}
}
file.close();
return file;
}
заголовочный файл
#ifndef SICT_AMAPRODUCT_H__
#define SICT_AMAPRODUCT_H__
#include "Streamable.h"
#include "Product.h"
#include "Date.h"
#include "ErrorMessage.h"
#include "general.h"
#include <iostream>
#include <fstream>
namespace sict{
class AmaProduct : public Product{
private:
char fileTag_;
char unit_[11];
protected:
ErrorMessage err_;
public:
AmaProduct(char file='N');
const char* unit()const;
void unit(const char* value);
fstream& store(fstream& file, bool addNewLine = true)const;
fstream& load(std::fstream& file);
ostream& write(ostream& os, bool linear)const;
istream& read(istream& is);
};
}
имя()
const char* Product::name()const{
return name_;
}
char* name_;
void Product::name(char* name){
delete[] name_;
name_= new char[strlen(name)+1];
strcpy(name_,name);
}
если кто-то заинтересован в других файлах я буду загружать их слишком
Меня не беспокоит чтение всего этого кода. Но читаете ли вы файл и используете тот же указатель –
_ «если кто-то заинтересован в других файлах, я их выгружу» _ Пожалуйста, нет! Уменьшите образец до [MCVE]. Пройдите через свой код с помощью отладчика. –
Что такое 'name()'? –