I have succesfully done this but with one error. using
...
ifstream input("infile.txt",ios::in)
while(input.good())
{
input.getline(file,100);
outputfile<<file<<endl;
}

then I have some new code that writes this into another file. You may laugh when you hear this but the problem is that it add an extra line to the output like:

from infile.txt
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer velit. Donec velit mauris, interdum nec, lacinia sed, aliquet eu, metus. Vivamus purus. Vestibulum euismod tortor ac ipsum. Maecenas nisl diam, sollicitudin ut, vehicula vitae, porta eleifend, mauris. Vestibulum luctus, enim sed accumsan accumsan, nisl purus vehicula turpis, quis viverra nunc lacus id dolor. Proin tortor. Suspendisse turpis ante, fringilla luctus, mollis a, dignissim eget, pede.

Vivamus sodales orci vitae magna tempor aliquet. Vestibulum semper, turpis eget luctus luctus, nisi erat rhoncus pede, ac mattis orci ante eu dolor. Donec sit amet nisl ac neque feugiat cursus. Suspendisse tempus. In consequat convallis arcu. Aliquam et ipsum. Integer sagittis mauris non

from extra code used to add data together above

is there a better method that doesn;t add a line at the end

Recommended Answers

All 2 Replies

Try this:
ifstream input("infile.txt")
while(input.getline(file,100))
{
outputfile<<file<<endl;
}

ios::in is the default for ifstreams so it's not needed. I can't say for sure but I bet the inflie.good() suffers from the same problem as !infile.eof() snippet that many peolp try, given it has the same outcome.

Try this:
ifstream input("infile.txt")
while(input.getline(file,100))
{
outputfile<<file<<endl;
}

ios::in is the default for ifstreams so it's not needed. I can't say for sure but I bet the inflie.good() suffers from the same problem as !infile.eof() snippet that many peolp try, given it has the same outcome.

worked like a charm thank you very much, SOLVED

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.