April 27th, 2010, 07:45 AM
How to know if Key in Vector does not exist / If File has write permissions
I have 2 questions to ask, and I decided to ask them in a single thread (to save space for the other forum goers).
1. How to find if a key in a vector doesnt exist?
Ex. There is a hash_map Dictionary defined Dictionary[<string>, <string>] (meaning the key is represented as a “string”, and the value is also a string
If I have something like this:
hash_map <string, string> Dictionary;
string doesNotExist = “does not exist”
string DictValue = Dictionary[doesNotExist];
It should identify that the Key for that Dictionary does not exist.
It does not error however, but it returns a blank string "". I want to identify if the key does not exist since it may be possible that the key exists but also contains a blank string "".
2. How to find if a file is writable to or not?
The problem I have is the file can be opened if it has read permissions but it cannot be written to since it has no write permissions. I am imagining something like this:
//write to the file
Printf(“Error: File is not writable”);
I tried searching but all I find is if the file exists, etc.
Thank you all for the future help!
Last edited by LeanA; April 27th, 2010 at 09:05 AM.
Reason: Clarification in question 1
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!