全新C++.处理用户输入
Brand new to C++. Handling user input
十年前,我在 VB.NET 写了一些应用程序,现在正试图自学C++。
我正在尝试弄清楚如何正确处理用户输入,并偶然发现了以下链接,该链接讨论了该主题以及为其他数据类型创建 GetInteger 函数等。
GetInteger(( @templatetypedef
我收到错误;"标识符'GetLine'未定义。 也许这是一个重载函数,它返回在另一节课中定义的字符串流? 任何方向将不胜感激。
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int GetInteger() {
while (true) {
stringstream converter;
converter << GetLine();
}
}
为了完成注释中所说的内容,您的代码还必须提供 GetLine:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string GetLine()
{
string result;
getline(cin, result);
return result;
}
int GetInteger() {
while (true) {
stringstream converter;
converter << GetLine();
}
}
但我也建议自己写一本好书或深入C++教程。 您可能会发现 C/C++ 与 .net 生态系统语言有很大不同
相关文章:
- C++如何通过用户输入删除列表元素
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何使用用户输入在C++中正确填充2D数组
- C++MySQL C api用户输入行
- 用户定义函数中的指针和输入
- 如何只允许用户输入正整数
- C++如何计算用户输入的数字中的偶数位数
- 通过for循环使用用户输入填充列表
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- 在C++中,我如何接受不同于同一行的用户输入
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 当用户键入分隔符时,停止getline()输入
- 通过错误处理,在C++中可靠地获得用户十六进制输入
- 当用户在qtablewidget中输入单元格时,如何获得信号?C++
- 显示基于用户输入的整数的字符
- 根据用户输入用字母填充矢量,并将"开始"和"结束"放在四肢
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 如果用户没有输入任何内容或输入错误,如何重新输入用户的输入?
- 为什么在代码块中执行时会跳过输入用户输入的行?
- 使用 for 循环在数组中输入用户