C++ 在C+;中进行输入时未检测到换行符+; >c; 如果(c=='\n') { cout
默认情况下,使用重载的C++ 在C+;中进行输入时未检测到换行符+; >c; 如果(c=='\n') { cout,c++,C++,默认情况下,使用重载的>运算符的所有输入都会跳过任何类型的空白。如果要读取空白,请使用操纵器(或设置适当的流标志).默认情况下,使用重载的>运算符的所有输入都会跳过任何类型的空白。如果要读取空白,请使用操纵器(或设置适当的流标志)。我认为以下内容对您有用: #include<iostream> #include<iomanip> bool treat_line(std::istream& is) { char c; while(is) {
>
运算符的所有输入都会跳过任何类型的空白。如果要读取空白,请使用操纵器(或设置适当的流标志).默认情况下,使用重载的>
运算符的所有输入都会跳过任何类型的空白。如果要读取空白,请使用操纵器(或设置适当的流标志)。我认为以下内容对您有用:
#include<iostream>
#include<iomanip>
bool treat_line(std::istream& is)
{
char c;
while(is)
{
is >> std::noskipws >> c;
if(c == '\n')
{
std::cout << "Newline\n";
break;
}
else
std::cout << c;
}
return bool(is); // convert "OK" state of stream to boolean
}
int main()
{
while(treat_line(std::cin))
;
std::cout << "done\n";
}
#包括
#包括
bool处理线(标准::istream&is)
{
字符c;
while(is)
{
is>>std::noskipws>>c;
如果(c=='\n')
{
std::cout以下是我认为对你有用的东西:
#include<iostream>
#include<iomanip>
bool treat_line(std::istream& is)
{
char c;
while(is)
{
is >> std::noskipws >> c;
if(c == '\n')
{
std::cout << "Newline\n";
break;
}
else
std::cout << c;
}
return bool(is); // convert "OK" state of stream to boolean
}
int main()
{
while(treat_line(std::cin))
;
std::cout << "done\n";
}
#包括
#包括
bool处理线(标准::istream&is)
{
字符c;
while(is)
{
is>>std::noskipws>>c;
如果(c=='\n')
{
STD::CUT< P> <强> GETLION>强>选项。GETLIN是C++中提供的一个标准库函数,用于从输入流读取字符串或行。
语法:
istream&getline(istream&is,string&str);
is-它是istream类的对象
str-它是存储输入的目标变量
示例程序:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str;
cout << "Please enter your name: \n";
getline (cin, str);
cout << "Hello, " << str ;
return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
字符串str;
CUT< P> <强> GETLION>强/ >选项。GETLIN是C++中提供的一个标准库函数,用于从输入流读取字符串或行。
语法:
istream&getline(istream&is,string&str);
is-它是istream类的对象
str-它是存储输入的目标变量
示例程序:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str;
cout << "Please enter your name: \n";
getline (cin, str);
cout << "Hello, " << str ;
return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
字符串str;
不能使用读取字符但不跳过空白的cin>>c;
(跳过空白)而使用读取字符但不跳过空白的cin.get(c)
而不是cin>>c;
(跳过空白)而使用读取字符但不跳过空白的cin.get(c)
。