How to determine if a string is a number with C++?

后端 未结 30 2494
遇见更好的自我
遇见更好的自我 2020-11-22 08:46

I\'ve had quite a bit of trouble trying to write a function that checks if a string is a number. For a game I am writing I just need to check if a line from the file I am r

30条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 09:08

    After consulting the documentation a bit more, I came up with an answer that supports my needs, but probably won't be as helpful for others. Here it is (without the annoying return true and return false statements :-) )

    bool isNumber(string line) 
    {
        return (atoi(line.c_str())); 
    }
    

提交回复
热议问题