pls wizards help a student

Write your question here.

Everytime the while loop finishes processing a string in this code it creates an extra empty string. How do I make it so that there is no empty string at the end of the loop?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  ifstream fin("A7infile.txt");
	
	while(getline(fin,line))
	{
		cout<<"Original Line: "<<line<<endl<<endl;
		breakup(line,first,middle,last);
		cout<<first<<" :is first"<<endl;
		cout<<middle<<" :is middle"<<endl;
		cout<<last<<" :is last\n"<<endl;
		neww=makealpha(first,middle,last);
		cout<<neww<<" :is the alphabetized line\n"<<endl;
	}
	fin.close();
	return 0;
}
Everytime the while loop finishes processing a string in this code it creates an extra empty string. How do I make it so that there is no empty string at the end of the loop?

I'm not even sure what the problem is. Does the empty string occur each iteration of the loop as the first sentence suggests or only on the final iteration of the loop as the second sentence suggests? How does this empty string manifest itself? Why? What should happen instead? What have you done to determine the cause of your problem?
No, it just occurs on the final iteration. I'm supposed to save the file instead of leaving a new line space. So I guess a better question may be how do I save the file or string before I leave the loop. I honestly have no clue what saving the file means, I was trying to use cin.get() to get rid of the newline space at the end but that doesn't work.
This is what I mean by an empty iteration.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Original Line: butterscotch zipper tang

butterscotch :is first
zipper :is middle
tang :is last

butterscotch tang zipper :is the alphabetized line

Original Line: lolipops And Rainbows

lolipops :is first
And :is middle
Rainbows :is last

And Rainbows lolipops :is the alphabetized line

Original Line:

 :is first
 :is middle
 :is last

 :is the alphabetized line

Process exited after 0.1981 seconds with return value 0
Press any key to continue . . .

Notice that the last lines have no words?
bump
Don't bump your post because it hasn't had a response in 30 minutes.

while(getline(fin,line) && !line.empty())

Topic archived. No new replies allowed.