全新C++.处理用户输入

Brand new to C++. Handling user input

本文关键字:输入 用户 处理 C++ 全新      更新时间:2023-10-16

十年前,我在 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 生态系统语言有很大不同