C++ string literials

Hi I've just recently begun working on a similar assignment to the one everyones having problems with. I've read through this forum and have been trying to piece together my own code from ideas from user posts. It seemed to be starting to work.
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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
	string filename;
	ifstream infile;

	//gets filename
	while (true){
    cout << "Please enter a filename: ";
    getline(cin, filename);
    infile.open( filename.c_str() );
		if ( infile.is_open() )	{
			break;
		}
    cout << filename << " is an invalid filename.\n";
	}
 
    char ch = 0;
	unsigned linenum = 1;
	
	while (infile.get( ch )) {
	
	////count line
	//cout.put( ch );
	//if (ch == '\n')	{
 //   cout << linenum << ": ";
 //   linenum++;
	//}		

	 switch (ch){
            case '/': 
                infile.get( ch );
                switch (ch){
                    case '/': 
                        while ((infile.get( ch )) && (ch != '\n'))
                        break;
                    }
                break;

            case '\"':
					while (infile.get(ch) && (ch!='"')){
						cout.put(ch);
					}
					break;

            case '\\': 
                break;

            default:
                break;
            }
        }
   

	}


My switch statement is obviously incomplete, but when I put the while loop inside case '\"': the program stopped reading my filename correctly and told me every filename I entered was incorrect.

I know theres already a topic on this I just need a quick response.
is Line 17 printing output ?, or is the switch not working?
if line 17 is printing out at the start of your program it's not the switch it will be something to do with the file, where it is placed, or the permissions it has.

you probably want a ';' at the end of line 37 as well.
Last edited on
Topic archived. No new replies allowed.