PDA

View Full Version : Copy a File with QT



undercover
13th February 2009, 16:18
Hello Guys,

I beginned programming with c++ a few month ago and since two weeks with qut... So im a newby :-)

I have written a source code with stl and i want to do the same thing with qt cause of the many options of qt library.

The Programm copy a file line for line... It would be better if its copy char for char, but i didn't find a good algorithm for that...

...So long I have two questions!

How can I programm this in QT (maybe somebody are so nice and write the code new :) ) that it read only char for char and not line for line . My other question is, is how i have to programm that, it makes a \n before the keyword i give him... I tryied in my code but without successs....

My english is also not good, so excuse me :-)


std::ifstream read(directory1);
std::ofstream write( "Keyword.lst" );

std::string line;

while (std::getline( read, line ) && line!="*NET*");

write <<"*Automatic*"<<std::endl<<std::endl;
write <<"*Test*"<<std::endl<<std::endl;

while ( !read.eof() )
{
std::getline(read, line);
if(line == "*keyword*"){
write <<' \n';
write << line<<std::endl;
}
else
write << line<<std::endl;
}

write.close();
read.close();

jpn
13th February 2009, 16:22
Take a look at QFile docs. There's an example of reading a file line by line in the detailed description.

undercover
13th February 2009, 16:28
But that is what i dont need, sorry maybe i impressed myself wrong :(

I want a reading char for char!

jpn
13th February 2009, 16:33
Ok, I'll give you a hint. QFile inherits QIODevice.