hey every body,
in my project-Emergency room Simulator- i should open file for all patient if he didnt have one, so, when the patient come,
i will ask him if he has a file, if yes, i will read his information and add some more in it, if not
i will open new file for him, i'll receve the patient as node of Queue, then i will write his information in a file.
this is my Code, and as u see there r problem with the concatenation of these strings then put it between quotationMark

void  read_patient_file(Patient &patient,string fn)
{

    string extention=".txt";
    string file_num;
    for (int d=0;d< fn.length();d++)
    file_num[d]=fn[d];
    string loction="C:\\";

    string file_name=loction+file_num+extention;

	ifstream infile;
	infile.open("file_name", ios::in);

    if(!infile)
      {
      	cout<<"file could not open";
        exit(1);
      }

         infile>>patient.name>>patient.age>>patient.gender>>patient.fileNumber>>patient.illness>>patient.degree;
         infile.close();
}
void patient_file(Patient patient)
{

    string file_num,extention,loction,file_name;

    extention=".txt";
    file_num=patient.fileNumber;
    loction="C:\\pateint";

    file_name=loction+file_num+extention;

    ofstream ofile ("file_name", ios::out);
    if(!ofile)
     {
    	cout<<"Can't open output file";
        exit(1);
     }

        ofile<<patient.name<<'  '<<patient.age<< '  '<<patient.gender<< '  '<<patient.fileNumber<< '  '<<patient.illness<< '  '<<patient.degree;
        ofile.close();
}

how could i solve this problem,
and if i want to gather all patient file in One fail (patient record) how could i do it?

void patient_record()//record of all patient
{
    ofstream ofile ("C:\\pateint.txt", ios::out);
    if(!ofile)
     {
    	cout<<"file could not open";
        exit(1);
     }
        ofile.close();
}

hope u can help me sooon
thank u

for (int d=0;d< fn.length();d++)
file_num[d]=fn[d];

Why not just use the assignment operator ? No need for that loop file_num = fn; >>string file_name=loction+file_num+extention;
That is a little odd. Why not use the fd parameter and delete the loop quoted above ? string file_name=loction+fn+extention; >>ofstream ofile ("file_name", ios::out);
Remove the quotes. Also delete ios::out because that's the default for ofstream ofstream ofile (file_name.c_str());

yas, right

i was traying to find another way to solve this problem and i've forget delete this part(for loop) :)

it work now..
but what if i want to gather all files in One file, how could i do it?

another question -and sorry-
here i have writ the patient information:

ofile<<patient.name<<'  '<<patient.age<< '  '<<patient.gender<< '  '<<patient.fileNumber<< '  '<<patient.illness<< '  '<<patient.degree;

but when i print it:
sera8224238224male82241238224akldf822458224441533782248224822482242280224

and this is read code:

if( !infile.eof() ) { // keep reading until end-of-file

      infile>>patient.name>>patient.age>>patient.gender>>patient.fileNumber>>patient.illness>>patient.degree;

        cout << "Patient information:";
        cout<<patient.name<<'  '<<patient.age<< '  '<<patient.gender<< '  '<<patient.fileNumber<< '  '<<patient.illness<< '  '<<patient.degree;
       }

how could i arrange the output?

thank u very very much : )

how could i arrange the output?

Use double quotation marks " " instead of ' ', for example;

ofile<<patient.name<<[B]" "[/B]<<patient.age<< [B]" "[/B] <<patient.gender<< [B]" "[/B] <<patient.fileNumber<< [B]" "[/B] <<patient.illness<< [B]" "[/B] <<patient.degree;

You can choose the length of the string as you wish.

>> but what if i want to gather all files in One file, how could i do it?
Write that file so that a single line of the file contains all data of a single patient.

mitrmkar

about .c_str()

what it does? i look to internt page which talk about it, but it wasn't clear :/

thank u again

about .c_str() what it does?

It returns a "const char *", a pointer to a null-terminated C-style string that the std::string internally holds. You should not modify the memory pointed by the pointer you get from calling c_str() i.e. consider it as read-only.

string str = "testing";
const char * ptr = str.c_str();
// the following prints out: testing
cout << ptr;

Here is one reference for std::string
http://www.cplusplus.com/reference/string/string/

This article has been dead for over six months. Start a new discussion instead.