S
SK
Hey folks,
I have some questions.
Could someone please answer them for me.
Problem background - I am parsing a text file. I need to find the
number of times an expression occured in the file.
[Q] >>> I open ifstream. Is there a need to explicitly close the
ifstream, i think not.
[Q] >>> I need to store the count of times an expression occured in
the file. I use map<std::string, long> as the data structure. Is there
some more efficient data structure.
[Q] >>> I have numbers stored in the form of strings in the txt file
like "12366555590". I need to have a count of numbers which have a
prefix of "123". I am forced to use std::string as storage for
"12366555590". Then i do strNumber.substr(0, 3) == "123" to check if
prefix is "123". Is there an efficient way I could do using arithmetic
types.
[Q] >>> All my TU's require <string>, only some require <algorithm>,
only some require <vector> etc. Is it a good idea to keep one common
header file and include in each TU. But this way I include unnecessary
headers in some TUs. Else i can keep a have a minimalist common header
file (with say <string>) and include in all TUs. Then each TU
explicitly includes <algorithm> or <vector>, whatsoever it requires.
Which is a better approach? I think second one.
[Q] >>> I can't anticipate all kinds of input files due to which
exceptions could be thrown. I have written two global handlers in
main catch(Exception& e), catch(...). Can I somehow also know which
line in the input text file was the reason for exception.
Thank you.
I have some questions.
Could someone please answer them for me.
Problem background - I am parsing a text file. I need to find the
number of times an expression occured in the file.
[Q] >>> I open ifstream. Is there a need to explicitly close the
ifstream, i think not.
[Q] >>> I need to store the count of times an expression occured in
the file. I use map<std::string, long> as the data structure. Is there
some more efficient data structure.
[Q] >>> I have numbers stored in the form of strings in the txt file
like "12366555590". I need to have a count of numbers which have a
prefix of "123". I am forced to use std::string as storage for
"12366555590". Then i do strNumber.substr(0, 3) == "123" to check if
prefix is "123". Is there an efficient way I could do using arithmetic
types.
[Q] >>> All my TU's require <string>, only some require <algorithm>,
only some require <vector> etc. Is it a good idea to keep one common
header file and include in each TU. But this way I include unnecessary
headers in some TUs. Else i can keep a have a minimalist common header
file (with say <string>) and include in all TUs. Then each TU
explicitly includes <algorithm> or <vector>, whatsoever it requires.
Which is a better approach? I think second one.
[Q] >>> I can't anticipate all kinds of input files due to which
exceptions could be thrown. I have written two global handlers in
main catch(Exception& e), catch(...). Can I somehow also know which
line in the input text file was the reason for exception.
Thank you.