Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

forse banale ma non ci riesco

0 views
Skip to first unread message

alod

unread,
Apr 22, 2003, 8:49:05 AM4/22/03
to
come fare per creare un file col nome di un campo intero di un oggetto?
ad esempio ho:

class Myclass{
...
int campointero;
...
}

e voglio:

Myclass m();
const char *c=(const char*)(m.campointero);
ofstream(c);

come dovrei fare invece?mi sa che combino casini coi puntatori...

Andrea Spadaccini

unread,
Apr 22, 2003, 9:00:56 AM4/22/03
to
alod wrote:

#include <sstream>
#include <string>
#include <fstream>

/*
codice
*/

ostringstream oss;
Myclass m;
oss << m.campointero;

string nomefile;
oss >> nomefile;
ofstream of(nomefile.c_str());

--
Andrea Spadaccini - Catania (Italy)
Mail: _lupin85...@libero.it - ICQ#: 91528290
. - Knowledge is not what you can remember, but what you cannot forget - .


Luc

unread,
Apr 22, 2003, 9:06:48 AM4/22/03
to
alod ha scritto...

> come fare per creare un file col nome di un campo intero di un oggetto?

char filename[...];
Myclass m;
sprintf(filename,"%d",m.campointero);

Non scomoderei gli stream per *SOLO* questo.

--
Luc.

Tommy

unread,
Apr 22, 2003, 9:27:57 AM4/22/03
to

"alod" <gse...@tiscalinet.it> wrote

Guarda questo esempio:

<CODE>
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
using namespace std;

int main()
{
string file_name;
stringstream ss;
int n=54;

ss << n;
ss >> file_name;

ofstream out(file_name.c_str());
// ......
out.close();

return 0;
}
</CODE>

Altrimenti puoi usare sprintf e varianti varie C-Like.

Tommy

Andrea Spadaccini

unread,
Apr 23, 2003, 9:44:50 AM4/23/03
to
Andrea Spadaccini wrote:

> ostringstream oss;

*error*
stringstream invece di ostringstream.

--
Andrea Spadaccini - Catania (Italy)
Mail: _lupin85...@libero.it - ICQ#: 91528290

. - I am not afraid of tomorrow, for I have seen yesterday and I love
today - .


0 new messages