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...
#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 - .
char filename[...];
Myclass m;
sprintf(filename,"%d",m.campointero);
Non scomoderei gli stream per *SOLO* questo.
--
Luc.
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
> 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 - .