相关疑难解决方法(0)

std :: cin用空格输入?

#include <string>

std::string input;
std::cin >> input;
Run Code Online (Sandbox Code Playgroud)

用户想要输入"Hello World".但是cin在两个词之间的空间失败了.我怎样才能cin完全接受Hello World

我实际上是用结构做这个,cin.getline似乎不起作用.这是我的代码:

struct cd
{
    std::string CDTitle[50];
    std::string Artist[50];
    int number_of_songs[50];
};

std::cin.getline(library.number_of_songs[libNumber], 250);
Run Code Online (Sandbox Code Playgroud)

这会产生错误.有任何想法吗?

c++ string space

129
推荐指数
7
解决办法
46万
查看次数

标签 统计

c++ ×1

space ×1

string ×1