Jump to content
  • Advertisement
Sign in to follow this  
bory

c++ inserting empty lines in a file

This topic is 5019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have a csv file which has always the following format: ########################### [1] General Data ;User_name ;User_password ;User_profile ;[2]General parameters ;;Id_info ;;Id_rule ;;Id_format ;;Id_number ;;[3]General declarations ;;;Var_number ;;;Var_type ;;;Var_name ;;;[4]General info ;;;;My_name ;;;;My_age etc... ########################### and I want to enter a new empty line after each line excepting the lines that have [1].....[100], and excepting the line with User_name For example I want that in the end my file to look like this: ########################### [1] General Data ;User_name ;User_password ;User_profile ;[2]General parameters ;;Id_info ;;Id_rule ;;Id_format ;;Id_number ;;[3]General declarations ;;;Var_number ;;;Var_type ;;;Var_name ;;;[4]General info ;;;;My_name ;;;;My_age etc... ########################### How do I do this? Thanks in advance, bory

Share this post


Link to post
Share on other sites
Advertisement
Hello,
I have done the following code but it doesn't eneter any new line in my file.
<code>
#include <string.h>
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
using namespace std;

int main (char* v, char** t)
{

ifstream input;
input.open("test0.csv");

const int MAXLINE=255;
char buffer[MAXLINE];

while ( !input.eof())
{
input.getline(buffer, MAXLINE);
string line(buffer);
int length=line.length();
for (int i=0; i<=length;i++)
{
if (line != '[')
{
cout << endl;
}
}
}
}
</code>
Thanks in advance,
bory

Share this post


Link to post
Share on other sites
I'm confused. Are you trying to write a file with empty lines or read a file that has empty lines? If the former is the case just do what the Jinjo said. In the latter you can just read the file line by line. I don't understand the need for your for statement at all.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!