Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,295 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,113 people online right now. Registration is fast and FREE... Join Now!




file handling...ofstream... could not find a built-in function that co

 
Reply to this topicStart new topic

file handling...ofstream... could not find a built-in function that co

imjuzaround
post 8 Mar, 2008 - 08:44 PM
Post #1


New D.I.C Head

*
Joined: 8 Mar, 2008
Posts: 16


My Contributions


[size=6][font=Tahoma]
[color=#333333]
i have my homework that is about file hanling...

Write a program that outputs its own C++ source file to a file called "WithoutComments.cpp" and to the screen, but omitting any of the comments enclosed in "/* ... */" markers (and omitting the markers themselves). The new program in the file "WithoutComments.cpp" should compile and run in exactly the same way as the program from which it was generated.

this is my code...

================================================
[/b][size=7]
nyl.cpp
[size=4]
<iostream>
<fstream>
<conio>
main()
{ /*every function should start with an open curly brace to indicate the starting of the func*/
char c; /*declaration of char c*/
ifstream file1; /*connects the ifstream "file1" to a following file.*/
ofstream file2;
file1.open("nyl.cpp");
file2.open("withoutcomments.cpp");
file1.get©;
while(!file1.eof()){
cout<<c;
file2.put©;
file1.get©;
}
file2.close();
file1.close();
return 0;
}


==============================================
my problem is that i could not find any built-in functions that coud omit
any statements inclosed in "/*...*/" markers....
could somebody help me with my homework??? tongue.gif




User is offlineProfile CardPM

Go to the top of the page

Nykc
post 8 Mar, 2008 - 08:56 PM
Post #2


sudo rm -R /

Group Icon
Joined: 14 Sep, 2007
Posts: 4,018



Thanked 12 times

Dream Kudos: 275
My Contributions


code.gif

So we can read this a little better.
User is offlineProfile CardPM

Go to the top of the page

nyl
post 8 Mar, 2008 - 10:35 PM
Post #3


New D.I.C Head

*
Joined: 28 Feb, 2008
Posts: 5

oh... im sorry... i forgot.. im in a haste... biggrin.gif

CODE

<iostream>
<fstream>
<conio>
main()
{ /*every function should start with an open curly brace to indicate the starting of the func*/
char c; /*declaration of char c*/
ifstream file1; /*connects the ifstream "file1" to a following file.*/
ofstream file2;
file1.open("nyl.cpp");
file2.open("withoutcomments.cpp");
file1.get(c);
while(!file1.eof()){
cout<<c;
file2.put(c);
file1.get(c);
}
file2.close();
file1.close();
return 0;
}
User is offlineProfile CardPM

Go to the top of the page

imjuzaround
post 8 Mar, 2008 - 10:47 PM
Post #4


New D.I.C Head

*
Joined: 8 Mar, 2008
Posts: 16


My Contributions


thank you nyl for making it clear for me....
smile.gif
User is offlineProfile CardPM

Go to the top of the page

captainhampton
post 10 Mar, 2008 - 06:27 AM
Post #5


Jawsome++;

Group Icon
Joined: 17 Oct, 2007
Posts: 518



Thanked 2 times

Dream Kudos: 825
My Contributions


Perhaps something like this could give you a push in the right direction for functions pertaining to opening/closing files:

cpp

ifstream infile;
infile.open ("test.txt");
if (infile.is_open())
{
while (infile.good())
cout << (char) infile.get();
infile.close();
}
else
{
cout << "Error opening file";
}
return 0;
User is offlineProfile CardPM

Go to the top of the page

imjuzaround
post 12 Mar, 2008 - 02:46 AM
Post #6


New D.I.C Head

*
Joined: 8 Mar, 2008
Posts: 16


My Contributions


yuh... i'm done with opening and closing file and copying characters into it....
i just dond know how to skip characters that are inclosed by certain flags or markers...
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 01:26AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month