String declaration issue..

Hey all,

I'm trying out my own way to vslidate a filename and i'm having problems from the start. The following line errors and says too many initializations or something:

const string NOT_ALLOWED_CHARS[9] = { "/", ":", ";", "*", "?", "\"", "<", ">", "|", "+" };

it's underlining the "+" as the flagged problem.

Also, have i got the "\"" correct? I'm trying to catch the " char - i tried """ but it said missing quotes..

Thanks,

Paul..
Last edited on
Its ok, sorted it, the index should be [10] not [9]

...but if someone could confirm if my "\"" is correct and will look for a " please :)
Several things spring to mind here.

The one which triggered the error message is that you are trying to put ten objects in nine boxes.

The other is the mismatch of what you are trying to do, which is to store a list of characters, and the type of object you are using, which is string, not char.

For example, you could just do this:
1
2
3
4
    const string NOT_ALLOWED_CHARS = "/:;*?\"<>|+";
    
    cout << "Length: " << NOT_ALLOWED_CHARS.size() << '\n' 
	 << NOT_ALLOWED_CHARS << '\n';

Length: 10
/:;*?"<>|+


See also string::find_first_of()

http://www.cplusplus.com/reference/string/string/find_first_of/
Last edited on
Hey Chevril, yeah i noticed the 10 into 9 thing haha but thanks for the heads up on find_first_of(), that worked perfectly..
Topic archived. No new replies allowed.