itoa function is not defined in cygwin so i need to define one manually listed below"found in net" but I have an error saying
'can not convert std:basic-string<char>,std::char-traits<char>,std::allocator<char>>' to char* in intilization'
, basically I want to read multi files in one function readfrom_policyfile which takes integer and return string or char and put it in in the filename like file0.txt, file1.txt
Which line hives that error ? I don't see and conversions to a char* here..
What I do see is string *filename = "file"+id+".txt"; which does not do what you want it to..
Also, to convert numbers to strings, you can use a stringstream.
Well, that pointer makes no sense. What you want is the actual string object, created by adding the things on the right. Other than that, it compiled fine for me.
(Though the error is saying something different. If it doesn't go away, try changing "file" to string("file")..)
Thanks hamsterma and Duoas for the quick reply,
Hi Duoas,
YOU ARE BRILLIANT DUOAS MATE it works good with the 1 st solution.
but still wondering why it does not work with the 2nd sol, leads to an error in the line code: ifstream myfile (filename); as described below
void policy::readfrom_policyfile(int id)
{
ostringstream oss;
oss << "file" << id << ".txt";
string filename = oss.str();
//printf("filename has %s",filename);
ifstream myfile (filename);// THE ERROR IS HERE NOW SAYING NO MATCHING FUNCTION CALL TO STD::BASIC-IFSTREAM<CHAR-STD::CHAR-TRANSIT<CHAR>::BASIC -IFSTREM()STD::STRING&)
int line;
int group[2];
int i=0;
if (myfile.is_open()){ ....
But it works good with the first proposed solution YOU ARE BRILLIANT DUOAS THANKS