本文介绍了我该如何输入包含数字和字符数据的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞!12345+67890 如何输入此行? 我尝试了什么: 我不知道任何关于这个...How to input this line?What I have tried:I DON'T KNOW ANYTHING REGAARDING THIS..推荐答案读取它作为一个字符串,然后 - 假设它不会总是在中间有一个+ - 将它处理成一个字符串集合:一个数字序列变成一个字符串,一个非数字序列变为另外。 在这种情况下,你最终会得到三个字符串:Read it as a string, then - assuming it won't always have a "+" in the middle - process it into a collection of strings: a sequence of numerics becomes a string, a sequence of non-numerics becomes another.In this case you will end up with three strings:"12345""+""67890"然后您可以将数字转换为数字,并使用开关语句计算表达式。 如果你逐步做到这一点并不困难 - 但这是你的功课,不是我的,所以我不会给你任何代码! 坐下来思考几分钟 - 它真的不像你想象的那么复杂。You can then convert the numerics to numbers, and work out the expression using a switch statement.It's not difficult if you do it stage by stage - but this is your homework, not mine, so I'll give you no code!Sit down and think about it for a few minutes - it's really not as complicated as you seem to think.为了你的功课,你需要向他们学习 C ++教程。 特别是你需要学习std的usful功能::字符串,如拆分和添加字符。For your homework you need to learn from some C++ tutorial.Especially you need to learn the usful functions of std::string like spliting and adding characters. Quote:如何输入这一行? 与其他任意字符串完全一样,输入为字符串。 处理完字符串后得到你想要的结果。Exactly like any other arbitrary string of chars, input as a string.And after you process the string to get the result you want. 这篇关于我该如何输入包含数字和字符数据的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-18 03:58
查看更多