CodeBlocks字符串输出定界线
CodeBlocks string output delimitered
我正在测试CodeBlocks中程序的字符串输出。这是代码:
#include <iostream>
#include <string>
using namespace std;
int main(){
string entry = "";
while(entry!="x"){
cout<<"Enter: ";
cin>>entry;
cout<<entry.substr(0,1)<<endl;
}
return 0;
}
但是,将结果打印好,好像是由空格和cout字符串" Enter"定界符,并以错误的订单的方式划定。什么是原因,我该如何解决这种情况?
Output:
Enter: P q r
P
Enter: q
Enter: r
Enter:
要读一行,不要使用 cin >> whatever
。当它遇到空格(空间,标签和纽文)时,它将停止阅读。使用std::getline()
:
getline(cin, entry);
现在这变成了:
assert(entry == "P q r");
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 意外输出..函数绑定在虚拟表中的发生方式
- 如何将QString绑定到QSQLQUERY,该呼叫过程输出VARCHAR
- CodeBlocks字符串输出定界线
- 使用C 从定界线拆分字符串中提取整数数组
- SEGFAULT与STD :: getline一起使用定界线
- 使用提升绑定输出地图数据
- 是否可以让一个应用程序配置和管理 DirectShow 筛选器,但将输出引脚绑定到另一个应用程序