PDA

View Full Version : Read Text file using structure..



umulingu
11th September 2009, 08:07
Hai

how to read Text file using structure.


struct commonDetails()
{
char *no=new char[6];
char *name=new char[10];
};
commonDetails cn;
QFile fileA(fileName);
fileA.open(QIODevice::ReadWrite);
QTextStream data(&fileA);
data>>cn;


but it is not working...
help please

umulingu
Banaglore

yogeshgokul
11th September 2009, 08:29
struct commonDetails()
{
char *no=new char[6];
char *name=new char[10];
};


Is it possible ?

You can use QDataStream.

wysota
11th September 2009, 09:34
QDataStream won't work as well unless you provide proper operators for the structure and unless the files was written using QDataStream as well.

umulingu
11th September 2009, 10:00
then how to do use structure?


and how to read continuous 5 characters[including space] in a text file..



QTextStream data(&fileA);
char *runno=new char[5];
data>>runno;

wysota
11th September 2009, 10:17
You can always do it like this:

QFile file(...);
file.open(QFile::ReadOnly);
QByteArray data = file.read(5);
strcpy(structure.no, data.constData());

nish
11th September 2009, 11:25
struct commonDetails()
{
char *no=new char[6];
char *name=new char[10];
};


WTF,,, is this a function or struct def? should i go back to school?

umulingu
14th September 2009, 12:21
hai


thanks for reply

but i didn't get.

umulingu
14th September 2009, 12:22
struct commonDetails()
{
char *no=new char[6];
char *name=new char[10];
};


WTF,,, is this a function or struct def? should i go back to school?

thanks for ur reply

But I didn't get...