Hallo everyone, I have some problems with my assignment. I asked to provide some error-handling in my program. What I want to ask abou how we handle an input that isn't its type. For example i define a variable int a but we "accidentally" input a string or other type. How we can handle that error type ? Thank you before
akira_shinizaki 0 Newbie Poster
Recommended Answers
Jump to PostOne of the other approaches is to never accept input as a numerical type. Only accept input as a string. Then parse the string after input for it's validity as a numeric value and convert the string to the numerical type as desired if it's valid.
Jump to PostWhile it's perfectly legitimate to parse the input string with a stringstream and the >> operator, it is not mandatory. Manual parsing will work. It may be tedious, but it will work.
All 8 Replies
ArkM 1,090 Postaholic
Lerner 582 Nearly a Posting Maven
akira_shinizaki 0 Newbie Poster
ArkM 1,090 Postaholic
Lerner 582 Nearly a Posting Maven
akira_shinizaki 0 Newbie Poster
Lerner 582 Nearly a Posting Maven
ArkM 1,090 Postaholic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.