473,466 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

file binary and template

Hi.

class whith Function generic for write binary files:

#include <fstream>

#include <iostream>

using namespace std;

#ifndef _FICHERO_H_

#define _FICHERO_H_

class Fichero{

private:

fstream fichero;

public:

bool f_existe(string nombre);

void f_crear(string nombre, bool oculto);

template <typename T> void f_escribir(string nombre, T dato);

};

#endif

bool Fichero::f_existe(string nombre){

bool ok = false;
fichero.open(nombre.c_str(), ios::in);

if(fichero.good())

ok = true;

fichero.close();

return ok;

}

void Fichero::f_crear(string nombre, bool oculto = false){

string auxiliar;
fichero.open(nombre.c_str(), ios::out);

fichero.close();
if(oculto){

auxiliar = "attrib +h " + nombre;

system(auxiliar.c_str());

}

}

/************************************************** ****************NOT
WRITE********************************************* **************************
****************************/

template <typename T> void Fichero::f_escribir(string nombre, T dato){

fichero.open(nombre.c_str(), ios::out | ios::binary);

fichero.write(reinterpret_cast<const char*>(&dato), sizeof(T));

fichero.close();

}

Thanks.
Jul 22 '05 #1
3 1084

"opotonil" <op******@hotmail.com> wrote in message
news:c8**********@filemon1.isp.telecable.es...
| Hi.
|
| class whith Function generic for write binary files:

[snip]

What's the question ?

Cheers.
Chris Val
Jul 22 '05 #2
Hi.

The function: template <typename T> void Fichero::f_escribir(string nombre,
T dato) not write in the file and i don´t know that it is bad.

Thanks
------------------------Spanish--------------------------
Hola

La funcion: template <typename T> void Fichero::f_escribir(string nombre, T
dato) no escribe nada en el fichero y no se que es lo que falla, el dato que
tendria que guardar es una estructura.

Gracias y salu2.

PD: existe algun buen grupo de noticias, como este, en español, mi ingles es
penoso.
Jul 22 '05 #3

"opotonil" <op******@hotmail.com> wrote in message
news:c8**********@filemon1.isp.telecable.es...
Hi.

The function: template <typename T> void Fichero::f_escribir(string nombre, T dato) not write in the file and i don´t know that it is bad.

Thanks


Try this

bool Fichero::f_existe(string nombre)
{
bool ok = false;
fichero.open(nombre.c_str(), ios::in);
if(fichero.good())
ok = true;
fichoro.clear(); // ***** clear the stream error state
fichero.close();
return ok;
}

If the file does not exist and you do not clear the error state, then
fichoro becomes unusable. You must always clear the stream after every error
if you want to use the stream again.

john
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: N. Graves | last post by:
Hey, I need to have a template ASP page that can dynamically include another file depending on that I call in the address. I have yet to make this work. Here is a sample of what I thought...
6
by: Nobody | last post by:
This is sort of my first attempt at writing a template container class, just wanted some feedback if everything looks kosher or if there can be any improvements. This is a template class for a...
0
by: Reed | last post by:
Can someone stear me in the right direction to convert a binary tree from a Linked List to a Dynamic Array... Dynamic arrays aren't something im strong with. //********bintree.h******** #ifndef...
5
by: Ruben Campos | last post by:
Some questions about this code: template <typename T> class MyTemplate; template <typename T> MyTemplate <T> operator- (const MyTemplate <T> & object); template <typename T> MyTemplate <T>...
6
by: Null Reference | last post by:
Anybody here who can explain or point me to a link ? I wish to create a blank MS Access DB file programmatically using C# . Thanks, nfs
1
by: Seth King | last post by:
I am used to programming in embedded C and I want to input a binary number into an int. usually I would just use bin as a suffix or b as a prefix int x = b001 or int x = 001110bin the hex...
9
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. ...
9
by: Leo jay | last post by:
i'd like to implement a class template to convert binary numbers to decimal at compile time. and my test cases are: BOOST_STATIC_ASSERT((bin<1111,1111,1111,1111>::value == 65535));...
18
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.