Click here to Skip to main content
15,902,893 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: class with static functions and variables Pin
ZoogieZork8-Nov-03 2:47
ZoogieZork8-Nov-03 2:47 
GeneralRe: class with static functions and variables Pin
Anonymous8-Nov-03 3:25
Anonymous8-Nov-03 3:25 
GeneralRe: class with static functions and variables Pin
Kuniva8-Nov-03 4:20
Kuniva8-Nov-03 4:20 
GeneralWin32 message window Pin
pranavamhari7-Nov-03 23:33
pranavamhari7-Nov-03 23:33 
GeneralRe: Win32 message window Pin
Antti Keskinen8-Nov-03 12:18
Antti Keskinen8-Nov-03 12:18 
GeneralRe: Win32 message window Pin
Peter Molnar8-Nov-03 13:37
Peter Molnar8-Nov-03 13:37 
GeneralRe: Win32 message window Pin
pranavamhari8-Nov-03 15:05
pranavamhari8-Nov-03 15:05 
QuestionDo streams always have to be passed by reference? Pin
Link26007-Nov-03 22:44
Link26007-Nov-03 22:44 
I don't understand why "copyLine(ifstream& fins, ofstream& fout)"?
Why copyLine function has to be passed by reference. The first
code is presented in textbook as an example, however, it doesn't
explain why copyLine must pass by reference. The second is rewritten
by me in attempting to use another apporach.(the apporach that does
not need to pass by reference) But the second one got an unresolved
fatal link error.

It is not that I don't like passing by reference, it is just that I don't
understand why they are passing by reference. Do streams always
have to be passed by reference?

<br />
///////////////////////////////////////////////////////////////////////////////<br />
void FileCopy()<br />
{<br />
	ifstream fin;<br />
	ofstream fout;<br />
<br />
	//Ask for the source file path<br />
	string inFile;<br />
	cout << "Please enter the input file name or path: ";<br />
	cin >> inFile;<br />
	fin.open(inFile.c_str());<br />
<br />
	//Ask for the destination file path<br />
	string outFile;<br />
	cout << "Please enter the destination file name or path: ";<br />
	cin >> outFile;<br />
	fout.open(outFile.c_str());<br />
<br />
	//Display error<br />
	if(fin.fail())<br />
	{<br />
		cerr << "error: cannot open " << inFile <br />
			<< " for input." << endl;<br />
		//return EXIT_FAILURE;<br />
	}<br />
<br />
	int lineCount = 0;<br />
	while(!fin.eof())<br />
	{<br />
		if (copyLine(fin, fout) != 0);<br />
		lineCount++;<br />
	}<br />
<br />
	cout << "Input file copied to output file." << endl;<br />
	cout << lineCount << " lines copied." << endl;<br />
<br />
<br />
}<br />
<br />
<br />
<br />
int copyLine(ifstream& fin,<br />
	     ofstream& fout)<br />
{<br />
	const char NWLN = '\n';<br />
	char nextCh;<br />
	int charCount = 0;<br />
<br />
	fin.get(nextCh);<br />
	while((nextCh != NWLN) && !fin.eof())<br />
	{<br />
		fout.put(nextCh);<br />
		charCount++;<br />
		fin.get(nextCh);<br />
	}<br />
<br />
	if(!fin.eof())<br />
	{<br />
		fout.put(NWLN);<br />
		charCount++;<br />
	}<br />
<br />
	return charCount;<br />
}<br />
<br />
////////////////////////////////////////////////////////////////////////<br />
int main()<br />
{<br />
	string inFile;<br />
	cout << "Please enter the input file name or path: ";<br />
	cin >> inFile;<br />
<br />
	string outFile;<br />
	cout << "Please enter the destination file name or path: ";<br />
	cin >> outFile;<br />
<br />
	copyLine(inFile, outFile);<br />
<br />
	return 0;<br />
}<br />
<br />
<br />
void FileCopy(string inFile, string outFile)<br />
{<br />
	ifstream ins;<br />
	ofstream outs;<br />
	<br />
	ins.open(inFile.c_str());	<br />
	if(ins.fail())<br />
	{<br />
		cerr << "error: cannot open " << inFile <br />
			 << " for input." << endl;<br />
	}<br />
<br />
	outs.open(outFile.c_str());<br />
	if(outs.fail())<br />
	{<br />
		cerr << "error: cannot open " << inFile <br />
			 << " for input." << endl;<br />
	}<br />
<br />
	while(!ins.eof())<br />
	{<br />
		const char NWLN = '\n';<br />
		char nextCh;<br />
<br />
		ins.get(nextCh);<br />
		while((nextCh != NWLN) && !ins.eof())<br />
		{<br />
			outs.put(nextCh);<br />
			ins.get(nextCh);<br />
		}<br />
<br />
		if(!ins.eof())<br />
		{<br />
			outs.put(NWLN);<br />
		}<br />
	}<br />
<br />
}<br />

AnswerRe: Do streams always have to be passed by reference? Pin
Andrew Walker8-Nov-03 13:17
Andrew Walker8-Nov-03 13:17 
General.lib in 6.0 Pin
LOSTTWARE.com7-Nov-03 21:11
LOSTTWARE.com7-Nov-03 21:11 
GeneralRe: .lib in 6.0 Pin
Mike Dimmick7-Nov-03 23:21
Mike Dimmick7-Nov-03 23:21 
GeneralChanging Printer Resolution at Run Time Pin
Tejas H Shah7-Nov-03 20:55
Tejas H Shah7-Nov-03 20:55 
GeneralLooping through all Outlook folders Pin
Anonymous7-Nov-03 20:33
Anonymous7-Nov-03 20:33 
GeneralLooping through all Outlook folders Pin
Anonymous7-Nov-03 20:33
Anonymous7-Nov-03 20:33 
GeneralRe: Looping through all Outlook folders Pin
Amit Dey8-Nov-03 0:43
Amit Dey8-Nov-03 0:43 
GeneralRe: Looping through all Outlook folders Pin
p_peto1-Jun-05 19:39
p_peto1-Jun-05 19:39 
GeneralDirectShow Video Standard Question Pin
Atif Mushtaq7-Nov-03 19:59
Atif Mushtaq7-Nov-03 19:59 
Generalredistribute crystal report 6.0 Pin
murali_utr7-Nov-03 18:30
murali_utr7-Nov-03 18:30 
GeneralRe: redistribute crystal report 6.0 Pin
Tejas H Shah7-Nov-03 21:38
Tejas H Shah7-Nov-03 21:38 
GeneralRe: redistribute crystal report 6.0 Pin
murali_utr7-Nov-03 22:09
murali_utr7-Nov-03 22:09 
GeneralRe: redistribute crystal report 6.0 Pin
Tejas H Shah7-Nov-03 23:41
Tejas H Shah7-Nov-03 23:41 
GeneralRe: redistribute crystal report 6.0 Pin
Jörgen Sigvardsson8-Nov-03 1:18
Jörgen Sigvardsson8-Nov-03 1:18 
GeneralRe: redistribute crystal report 6.0 Pin
Anthony_Yio9-Nov-03 19:45
Anthony_Yio9-Nov-03 19:45 
QuestionHow can get CD-ROM(DVD-ROM) Informations in Windwos Platform? Pin
HansonDavid7-Nov-03 17:51
HansonDavid7-Nov-03 17:51 
AnswerRe: How can get CD-ROM(DVD-ROM) Informations in Windwos Platform? Pin
Ahmed Galal8-Nov-03 2:42
Ahmed Galal8-Nov-03 2:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.