Outfile

Having issues with my output file. After I send the infile through the pig latin converter it doesn't output the translated words.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include <string>
#include <fstream>


using namespace std;

bool isVowel(char);
string rotate(string);
string plString(string);

int main()
{ 

	string str;
	ifstream infile;
	ofstream outfile;

	infile.open("input.txt");
	outfile.open("output.txt");

	infile >> str;
	while(infile)
	{
		cout << plString(str) << " ";
		infile >> str;
	}

	


	cout << endl;
	system("pause");
	return 0; 



}
	



bool isVowel(char ch)
{
    switch (ch)
    {
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':
    case 'Y':
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
    case 'y':
        return true;
    default:
        return false;
    }
}

string rotate(string str)
{
    string::size_type len = str.length();

    string str1;

    str1 = str.substr(1, len - 1) + str[0];

    return str1;
}

string plString(string str)
{
    string::size_type len;

    bool Vowel;

    string::size_type counter;

    if (isVowel(str[0]))                       //Step 1
        str = str + "-yay";
    else                                        //Step 2
    {
        str = str + '-';
        str = rotate(str);                    //Step 3

        len = str.length();                    //Step 3.a
        Vowel = false;                     //Step 3.b

        for (counter = 1; counter < len - 1;
                          counter++)            //Step 3.d
            if (isVowel(str[0]))
            {
               Vowel = true;
                break;
            }
            else                                //Step 3.c
                str = rotate(str);

        if (!Vowel)                        //Step 4
            str = str.substr(1, len) + "-way";
        else
            str = str + "ay";
    }

    return str;           
	

}
outfile << str.length[500]<< endl;
it doesn't output the translated words.

Where do you write the translated words to the output file?
One would think you would do this after line 25.

Line 114: What is this? It does not belong.

23
24
25
26
27
28
29
	string pig_word;
	while(infile)
	{   pig_word = plString(str);
		cout << pig_word << " ";
		outfile << pig_word << " ";    //  Write to output file 
		infile >> str;
	}


When the code is being read in (infile) and output to the outfile there is no spaces in between the words. How would i go about fixing that?
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>
#include <string>
#include <fstream>


using namespace std;

bool isVowel(char);
string rotate(string);
string plString(string);
	ifstream infile;
	ofstream outfile;

int main()
{ 

	string str;


	infile.open("input.txt");
	outfile.open("output.txt");

	string str;
	while(infile)
	{
		str = plString(str);
		cout << str << " ";
		outfile << str << " ";
		infile >> str;

	}

	


	cout << endl;
	system("pause");
	return 0; 



}
	



bool isVowel(char ch)
{
    switch (ch)
    {
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':
    case 'Y':
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
    case 'y':
        return true;
    default:
        return false;
    }
}

string rotate(string str)
{
    string::size_type len = str.length();

    string str1;

    str1 = str.substr(1, len - 1) + str[0];

    return str1;
}

string plString(string str)
{
    string::size_type len;

    bool Vowel;

    string::size_type counter;

    if (isVowel(str[0]))                       //Step 1
        str = str + "-yay";
    else                                        //Step 2
    {
        str = str + '-';
        str = rotate(str);                    //Step 3

        len = str.length();                    //Step 3.a
        Vowel = false;                     //Step 3.b

        for (counter = 1; counter < len - 1;
                          counter++)            //Step 3.d
            if (isVowel(str[0]))
            {
               Vowel = true;
                break;
            }
            else                                //Step 3.c
                str = rotate(str);

        if (!Vowel)                        //Step 4
            str = str.substr(1, len) + "-way";
        else
            str = str + "ay";

		
    }

    return str;           
	

}

Line 28: You're clearing writing a space after each word.

Have you tried purging the file to make sure you're not looking at old output.
I update the file every time i debug the program.
Topic archived. No new replies allowed.