How to make a file reader NOT read the contents of the file?

I have been coding C++ for a few days, and I'm learning it pretty fast, and I'm making an audio converter, so that you can convert AC3 to MP3, etc.
I wanted to start learning another language, I already know Java, HTML, CSS, and a bit of PHP.
It's going pretty good, but my file reader actually shows the content IN the file, which I don't want, because that ends up showing all the weird text with the video file, I tried system("CLS"); after the file gets read, but that didn't help at all.
Here's the code, I apologize for how messy it is;
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <cstdlib>

using namespace std;

void converterMain()
{
    /**
    * Variables
    */
    char word[50];
    int strength;
    int bitrate;
    int resolution;
    string filename;
    char filenamesolid[50];
    ifstream file;
    string sound;
    string video;
    string yn = "y/n";
    int percent;
    string percentage = "%";
    
    /**
    * Console Output
    */
    cout << "Enter the name of the file you wish to convert, the file must be in the same \ndirectory as this converter" << endl;
    cout << "\nFilename: ";
    
    /**
    * File Reader
    */
    cin.getline(filenamesolid, 50);
    file.open(filenamesolid);
    if(!file.is_open())
    {
        exit(EXIT_FAILURE);
    }
    file >> word;
    while(file.good())
    {
        cout << word << " ";
        file >> word;
    }
    
    /**
    * Console Output
    */
    cout << "\nLoaded file: " << filenamesolid;
    cout << "\n\n";
    cout << "Strength of conversion, will effect audio and display, the less strength, the \nfaster it will convert, the more strength, the better the audio & video will be";
    cout << "\n\nStrength: ";
    
    /**
    * Console Input
    */
    cin >> strength;
    
    /**
    * Console Output
    */
    cout << "You have selected to convert with the strength of: " << strength;
    cout << "\n\n";
    cout << "Bitrate that the video file has\n\n";
    cout << "Bitrate: ";
    
    /**
    * Console Input
    */
    cin >> bitrate;
    
    /**
    * Console Output
    */
    cout << "You have selected the bitrate: " << bitrate;
    cout << "\n\n";
    cout << "Resolution of the video file\n\n";
    cout << "Resolution: ";
    
    /**
    * Console Input
    */
    cin >> resolution;
    
    /**
    * Console Output
    */
    cout << "You have selected the resolution: " << resolution << endl << endl;
    cout << "Video type you want to convert to: ";
    
    /**
    * Console Input
    */
    cin >> video;
    
    /**
    * Console Output
    */
    cout << "\nVideo type will be converted to: " << video << endl;
    cout << "Sound type you want to convert to: ";
    
    /**
    * Console Input
    */
    cin >> sound;
    
    /**
    * Console Output
    */
    cout << "\nSound type will be converted to: " << sound << endl;
    cout << "\n\nDo you still want to convert? (Y/n)\n";
    
    /**
    * Console Input
    */
    cin >> yn;
    
    /**
    * Command Listener
    */
    if(yn == "y")
    {
        while(percent <= 100)
        {
           cout << "\nConverting (" << percent << percentage;
           cout << ")" << endl;
           percent++;
           sleep(1);
        }
    }
    if(yn == "n")
    {
        cout << "Quiting..." << endl;
        sleep(1);
        exit(EXIT_SUCCESS);
    }
}

int main()
{
    converterMain();
    return 0;
}


Thank you for any help you may give me. Also, please don't give me code, I want to learn, not skid.
closed account (o3hC5Di1)
Hi there,

I don't really get this bit:

1
2
3
4
5
6
file >> word;
    while(file.good())
    {
        cout << word << " ";
        file >> word;
    }


If you don't want the file contents to be printed (i.e. sent to std::cout) then why do you do: cout << word after doing [file >>word[/code] ?

Also, if you're trying to read the entire file into word[], I suggest you use .read(): http://cplusplus.com/reference/iostream/istream/read/

Hope that helps.

All the best,
NwN
Mhm, thanks, I fixed the problem anyway.
Topic archived. No new replies allowed.