【发布时间】:2016-11-29 00:07:00
【问题描述】:
我想用VC输入一个字符串,但是getline函数似乎不起作用,当我运行我的程序时,“cin”部分被跳过了。这是我的代码
printf("Exercise 1\n");
printf("Please enter the sentence you want\n");
char str[256];
std::cin.getline(str, 256);
std::cout << str;
这是我的标题
#include <iostream>
#include <string>
#include <bitset>
我在使用 VS2015 社区,我的编译器有什么问题吗?
【问题讨论】:
-
char str[256];->std::string str;,std::cin.getline(str, 256);->std::getline(std::cin, str);和天空又是蓝色的。 -
买一本不同的书。您应该将
std::string用于string 和文本。
标签: c++ visual-studio visual-c++