Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new in C++. I am using C++ 98.Here is my code. It is getting the text from a `lineEdit` of a Qt4 form.

strcpy(Name,ui->lineEdit->setText(QString::fromStdString(Name)) );
strcpy(Class,ui->lineEdit_1->setText(QString::fromStdString(Class)));
strcpy(Grade,ui->lineEdit_2->setText(QString::fromStdString(Grade)));

std::ofstream myfile;
myfile.open(mypath,std::fstream::in | std::fstream::out );
myfile<<Name<<"\t"<<"Name"<<"\n";
myfile<<Class<<"\t"<<"Class"<<"\n";
myfile<<Grade<<"\t"<<"Grade"<<"\n";




Here is 2 column space separated text file `sample.conf`:
Quote:



AA. Name
BB Class
CC Grade


It is updating the file correctly

My question is there any way to write above text file in without using delimiter like in the above case is \t .

By using other datatype in like FILE or ofstream or some other that don't use delimiter(\t) for writing file ?

That can directly write to file column

What I have tried:

Note:
My purpose is not restrict file to it's delimiter
Posted
Updated 21-Dec-22 23:40pm
Comments
Richard MacCutchan 22-Dec-22 6:12am    
No. Text files are free form and have no concept of columns. You will have to reformat the text when you read the file to display it.

1 solution

Do you mean 'align the columns without using tabs'?
If that is the case, then you have to read the file twice: the first time for finding the maximum column lengths. The second time to produce the output, using the appropriate number of blanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900