string empty line

hi

How can a string recognize an empty line? I'm having an issue debugging because my while loop gets stuck when ever it reaches an empty line (its seems as if strings dont have an 'endl' detector ).

What can I do to let it skip the empty line? Its causing a massive memory leak when that happens (saw it using the debugger).

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
while(!FI_ZumaLv1.eof())
	{
		//KING POSITION
		if (sGetInput == "K") 
		{   
			    		pdKingPosition = new double [ikelements]; //get the king's coordinates
						FI_ZumaLv1 >> pdKingPosition[ikelements];
						ikelements++;
					    FI_ZumaLv1 >> pdKingPosition[ikelements];
						ikelements++;
		}

		//FIRST SPLINE ORBIT  
		if (sGetInput == "O1")
		{ adFirstOrbit = new double[ielemnts1];
			FI_ZumaLv1 >> adFirstOrbit[ielemnts1];
			ielemnts1++;
			FI_ZumaLv1 >> adFirstOrbit[ielemnts1];
			ielemnts1++;
		}

		//SECOND SPLINE ORBIT
		if (sGetInput == "O2")
		{	adSecondOrbit = new double[ielemnts2];
			FI_ZumaLv1 >> adSecondOrbit[ielemnts2];
			ielemnts2++;
			FI_ZumaLv1 >> adSecondOrbit[ielemnts2];
			ielemnts2++;
		}

		//THIRD SPLINE ORBIT
		if (sGetInput == "O3")
		{	adThirdOrbit = new double[ielemnts3];
			FI_ZumaLv1 >> adThirdOrbit[ielemnts3];
			ielemnts3++;
			FI_ZumaLv1 >> adThirdOrbit[ielemnts3];
			ielemnts3++;
		}
		//go to new line on black space
		
			FI_ZumaLv1 >> sGetInput;
	}
Have you tried std::string.empty()?
What does "string.empty()"do would it immediately go to a new line?
Is sGetInout initialized before you enter your while loop?

As you are using == in all cases, you could tweak your if statements to use else

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
26
27
28
29
30
31
		if (sGetInput.empty())  // or even sGetInput == "K"
		{   
		        // DO NOTHING
		}

		//KING POSITION
		else if (sGetInput == "K") 
		{   
		        // do stuff
		}

		//FIRST SPLINE ORBIT  
		else if (sGetInput == "O1")
		{
		        // do stuff
		}

		//SECOND SPLINE ORBIT
		else if (sGetInput == "O2")
		{
		        // do stuff
		}

		//THIRD SPLINE ORBIT
		else if (sGetInput == "O3")
		{
		        // do stuff
		}
		//go to new line on black space

		....

Last edited on
Why does does ifstream stop when it reaches an empty line? (this isn't the end of my file though) this ends up producing a stack overflow.

And yes it was initialized. The problem is that its seems to be fine at reading the file till its gets to the empty line dividing KING DATA, ORBIT 1...
Last edited on
Topic archived. No new replies allowed.