Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 关于while循环练习的问题 intmain() { 整字数=0; int prevnum=-1; 字符串previous=“”; 串电流; 而(cin>>当前) { ++字数; 如果(先前==当前) { 试试这个: int main() { int nu_C++_While Loop - Fatal编程技术网

C++ 关于while循环练习的问题 intmain() { 整字数=0; int prevnum=-1; 字符串previous=“”; 串电流; 而(cin>>当前) { ++字数; 如果(先前==当前) { 试试这个: int main() { int nu

C++ 关于while循环练习的问题 intmain() { 整字数=0; int prevnum=-1; 字符串previous=“”; 串电流; 而(cin>>当前) { ++字数; 如果(先前==当前) { 试试这个: int main() { int nu,c++,while-loop,C++,While Loop,关于while循环练习的问题 intmain() { 整字数=0; int prevnum=-1; 字符串previous=“”; 串电流; 而(cin>>当前) { ++字数; 如果(先前==当前) { 试试这个: int main() { int number_of_words = 0; int prevnum = -1; string previous = ""; string current; while (cin >> current) { ++number_of_

关于while循环练习的问题
intmain()
{
整字数=0;
int prevnum=-1;
字符串previous=“”;
串电流;
而(cin>>当前)
{
++字数;
如果(先前==当前)
{
试试这个:

int main()
{
int number_of_words = 0;
int prevnum = -1;
string previous = "";
string current;
while (cin >> current)
{
    ++number_of_words;
    if (previous == current)
    {
        cout << "word number: " << number_of_words << "\n"
            << "Repeated Word: " << current << "\n";
        previous = current;
    }
    else while (prevnum == number_of_words)
    {
        number_of_words = 0;
        prevnum = 0;
        break;
    }
}
}
#包括
#包括
#包括
使用名称空间std;
int main()
{
字数;
串前;
串电流,输入;
while(true)
{
先前的=”;
单词的数量=0;
(电流)
{
++字数;
如果(先前==当前)

问题是否不清楚?添加给您带来麻烦的代码,因为直到上一条语句之后才能转到if条件。但如果您不将括号放在if条件之外,则previous不属于您的if条件。对吗?我不理解问题…在一种情况下,您始终执行“previous=current”(如果未验证if条件,也可以执行)对不起,我试着把我的问题说得更清楚了。我想你是说
else if
而不是
else while
#include <sstream>
#include <string>
#include <iostream>
using namespace std;

int main()
{

    int number_of_words;
    string previous;
    string current, input;

    while (true)
    {
        previous = "";
        number_of_words = 0;
        cout << "\nWrite the data\n";
        getline(std::cin, input);
        stringstream ss;
        ss << input; 
        while (ss >> current)
        {
            ++number_of_words;
            if (previous == current)
                cout << "word number: " << number_of_words << "\n"
                    << "Repeated Word: " << current << "\n";
            previous = current;
        }
    }
}