[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: (Off topic) warning: ANSI C++ forbids variable-size array `theData'
From:       Malte.Starostik () t-online ! de (Malte Starostik)
Date:       2001-06-24 9:44:35
[Download RAW message or body]

On Sonntag, 24. Juni 2001 07:19, Ian Reinhart Geiser wrote:
> Greetings,
> 	I have a question on the correct way of doing things.
> 	I have a byte array that is a char[].  The problem is i do not know the
> 	length until runtime.  I have always done this but C++ is not suppose to
> 	be this way.
>
> 	Currently I am doing the following:
>
> 	char data[blockSize];	// Is there a better way to do this....
>             theFile->at(theSession->getIndex());
>             int newbytesWritten = theFile->readBlock(data, blockSize);
>
> 	I know there is a better way to do this, but I cannot find it right now.
> 	Any suggestions?
QByteArray data(blockSize);
theFile->at(theSession->getIndex());
int newbytesWritten = theFile->readBlock(data.data(), blockSize);

With QByteArray you can also easily resize the data etc.
-Malte
-- 
.globl main; main:
.long 0x90909090,0xdb311deb,0x89d98843,0x89e2d3da,0x01e0d3d0,0x92548dc2
.long 0x80cd5902,0xd889db31,0xe880cd40,0xffffffde,0x206c6c41,0x72756f79
.long 0x73614220,0x72412065,0x65422065,0x676e6f6c,0x206f7420,0x0a217355

 
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic