如何使用cin.get()而不仅仅是cin
How to use cin.get() instead of just cin?
我试图创建一个凯撒密码,但是当我输入我的消息时,cin
不接受空格,只接受第一个单词。我的老师告诉我用cin.get()
而不是cin.getline()
。在这种情况下我如何使用cin.get()
?
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include "unistd.h"
using namespace std;
int main(int argc, char **argv){
string message = "Empty";
int opt = 0;
int rotation = 0;
extern char *optarg;
static const char* opt_string = "r:f:h";
opt = getopt( argc, argv, opt_string);
while(opt != -1)
{
switch (opt)
{
case 'r':
rotation = atoi(optarg);
cin >> message;
for(int x = 0; x<message.length(); x++)
message[x] = message[x] + rotation;
cout << message << endl;
break;
}
opt = getopt( argc, argv, opt_string);
}
}
下面是关于cin的解释。得到:http://www.cplusplus.com/reference/istream/istream/get/
您应该将cin >> message
替换为cin.get (message,size_of_max_aprox_input)
相关文章:
- 为什么这个案例陈述需要一个"if else"而不仅仅是一个"if"?
- std::find,返回所有找到的值的替代方法,而不仅仅是存在重复的向量的第一个值
- 为什么C++总是显示十六进制内存地址,而不仅仅是整数?
- 为什么我们要做"INT_MAX/10"而不仅仅是INT_MAX?
- 为什么 std::vector 需要 is_trivial 才能按位移动,而不仅仅是is_trivially_copya
- 为什么在这个C++问题中使用const_iterator而不仅仅是迭代器?
- C++,从文件读取到结构,然后读取到向量(结构被推入向量太多次,而不仅仅是一次)
- 如果要求比较器是严格的总排序,而不仅仅是严格的弱排序,C++标准算法会更快吗?
- 为什么我们必须在 C++ 中释放数组数组,而不仅仅是整个"matrix"
- 十进制文字不仅仅是LONG_LONG_MAX
- 为什么非放置"新建"和"删除"内置于语言中,而不仅仅是常规函数?
- 使用 fstream 在空格分隔文件中查看下一项(不仅仅是一个字符)的方法
- 这是循环击中两个输出,而不仅仅是我期望的输出
- 在C++中,是否有任何理由生成并立即加入线程,而不仅仅是直接调用函数?
- 如何正确抛出一个需要的不仅仅是构造函数的异常
- 为什么 cppreference 将type_traits xxx_v快捷方式定义为内联 constexpr,而不仅仅是
- C++Qt创建者,我可以评论每一行,而不仅仅是评论选择
- 为什么BOOST.PROGROGROGOTIONS不仅仅是标头
- 使用FP:快速导致错误的VC 结果(不仅仅是不准确)结果 - 这是编译器错误
- 如何使用cin.get()而不仅仅是cin