C++ 如何在VC中输入字符串

C++ 如何在VC中输入字符串,c++,visual-studio,visual-c++,C++,Visual Studio,Visual C++,我想用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> #includ

我想用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::cin >> str;


字符str[256];->std::string str,std::cin.getlinestr,256;->std::getlinestd::cin,str;天空又变蓝了。换一本不同的书。您应该使用std::string作为字符串和文本。我以前做过。但是我需要对字符串中的单词和字符进行计数,需要跳过两个单词之间的空格。这就是我使用getline函数的原因。那么我该怎么做呢?顺便说一句,std::cin>>mystring只会读一个单词。要获取enter文本行,必须使用std::getline。我明白了。编辑。谢谢你的评论@ThomasMatthews@D.Kenny:关于这一点,请参阅下文中最多的1800+答案和拆分字符串。
string mystring;
std::getline (std::cin,mystring);