5 Replies - 497 Views - Last Post: 23 May 2009 - 06:44 AM Rate Topic: -----

#1 pradosh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 20-May 07

I am trying to write code for my I/O program. I would like to have yo

Posted 23 May 2009 - 05:25 AM

write a program where you will write certain lines to a file.In the second step you need to read the file and write it to an other file removing all the line breaks in the previous file.

Eg. ram.txt
---------------
I am a boy.
I am a girl.
I am a man.

hari.txt
-------------
I am a boy.I am a girl. I am a man.


what I tried





#include <fstream>
#include<cstdio>
#include<iostream>
using namespace std;

int main()
{
fstream File("dump.txt",ios::in | ios::out);
File << "Hi!  how's  going I am allright";
File<<" \n how are you doing?   \n life is going good   \n hi what about  you?";
 //put "Hi!" in the file
static char str[10]; //when using static, the array is automatically

char ch;
//initialized, and very cell NULLed
File.seekg(ios::beg); //get back to the beginning of the file
//this function is explained a bit later

/*
while(!File.eof()){
		  File >> str;
		  cout << str;
}
*/ // word  by  word  read

while (!File.eof()){
	  File.get(ch);
	  if(ch=='\n'){
				   ch=' ';}
	  cout<<ch;
	  }


File.close();
getchar();
return 0;
}




Here I have been able to write to the same file Dump.txt without line break. But I want it to write it to another file without line break.

Is This A Good Question/Topic? 0
  • +

Replies To: I am trying to write code for my I/O program. I would like to have yo

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: I am trying to write code for my I/O program. I would like to have yo

Posted 23 May 2009 - 05:35 AM

Just open a filestream to a new file and write to it.

If you have written the code you have supplied it should be a fairly simple step.

1 - Have a read here
http://www.cplusplus...tutorial/files/

2 - Try and write to a new file.

3 - Get back to us with the details of what about writing ot the new file is causing you trouble or confusion.
Was This Post Helpful? 0
  • +
  • -

#3 pradosh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 20-May 07

Re: I am trying to write code for my I/O program. I would like to have yo

Posted 23 May 2009 - 05:45 AM

My friend Janotte .. .i wrote the modified code according your advice.i hope you thought this way .



#include <fstream>
#include<cstdio>
#include<iostream>
using namespace std;

int main()
{
fstream File("dump.txt",ios::in | ios::out);
File << "Hi!  how's  going I am allright";
File<<" \n how are you doing?   \n life is going good   \n hi what about  you?";
 //put "Hi!" in the file
static char str[10]; //when using static, the array is automatically

char ch;
//initialized, and very cell NULLed
File.seekg(ios::beg); //get back to the beginning of the file
//this function is explained a bit later

/*
while(!File.eof()){
		  File >> str;
		  cout << str;
}
*/ // word  by  word  read

// Janotte....I made the changes here  

ofstream myfile;
myfile.open ("example.txt");   //opening of a new file.
while (!File.eof()){
	  File.get(ch);
	  if(ch=='\n'){
				   ch=' ';}
	  
	  myfile << ch;
	  
	  }

myfile.close();
File.close();
getchar();
return 0;
}



Was This Post Helpful? 0
  • +
  • -

#4 pradosh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 20-May 07

Re: I am trying to write code for my I/O program. I would like to have yo

Posted 23 May 2009 - 05:50 AM

I have another doubt that is really getting me troubled. As in java we can do two operation simultaneously by using thread and synchronise .

write a program where one process will read from one file .At the same time another process will use this content for another purpose at the same time.[size=1]
I am not able make out ....is there a thread way to solve such problem.!!!
Was This Post Helpful? 0
  • +
  • -

#5 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: I am trying to write code for my I/O program. I would like to have yo

Posted 23 May 2009 - 06:07 AM

There certainly are threads in C++
Have a read here for more information
http://www.linuxself...g-HOWTO-18.html
Was This Post Helpful? 0
  • +
  • -

#6 pradosh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 20-May 07

Re: I am trying to write code for my I/O program. I would like to have yo

Posted 23 May 2009 - 06:44 AM

I want more concrete help on this thread thing concerned to my program.I will be glad if you will put your idea and note down your thought on it.But i am reading that given site.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1