is there a way to contain the text in a normal format when writing out to a text file? By this i mean, if i have cout output a million a's, instead of one long line if u open and view the txt file, it is many rows.

Thanks

Recommended Answers

All 6 Replies

while(0 < 1)
{
       stream_out<<"a ";
}

#2 will print out more than a million a+space i guess...
clutchkiller:
When you have a file with a million 'a' characters in it and you want to see it (most of the time on a screen) then there is a problem. A screen has it's fysical limitations. Luckily there is something wich is called wrapping. The software normaly takes care of that(or not,depends)
But wrapping lets us see a string of a's as if it where multiple lines.
In reality it is just one long bunch of a's one after the other.

Sorry lol, a million a's was just an exaggerated expression to get a point across. And i dont understand what solution you guys have given me. sorry =(

when you output to your file, the text editor that you open the file with (notepad for example) will have an option to automatically wrap the words to the size of the window. If you want the lines to wrap at a certain set length, add something like:

int count = 0;
while(0 < 1)
{
       stream_out<<"a ";
       
       if (count % 10 == 0)           // the 10 here is the number to change in order to set the number  
             stream_out<<endl;       //of chars to put before the line break
           
       count++;
}

what that will do is put a line break every 10 times an 'a' is output to the file. The number 10 on the first commented line is the number that sets how many characters are output before the line break is placed.

is there a way to contain the text in a normal format when writing out to a text file?

Yes, you can make your own class that inherits from ostream.

when you output to your file, the text editor that you open the file with (notepad for example) will have an option to automatically wrap the words to the size of the window. If you want the lines to wrap at a certain set length, add something like:

int count = 0;
while(0 < 1)
{
       stream_out<<"a ";
       
       if (count % 10 == 0)           // the 10 here is the number to change in order to set the number  
             stream_out<<endl;       //of chars to put before the line break
           
       count++;
}

what that will do is put a line break every 10 times an 'a' is output to the file. The number 10 on the first commented line is the number that sets how many characters are output before the line break is placed.

nifty! thanks a lot

Ima save this source as a snippet =D

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.