Do not use using namespace std

Today wrote such a small program error, error: count is not clear

#include "stdafx.h"
#include<iostream>
using namespace std;

int count = 0;

int main()
{
    for (int i = 0; i < 10; i++)
    {
        static  int number = 0;
        for (int j = i; j < 10; j++)
        {
            number++;
            cout << number << endl;
            count++;
        }


    }


    cout << count << endl;
}

Later found global variables defined inside std count and has repeated the name, so in order to avoid this, spend more time with
using std :: write

#include "stdafx.h"
#include<iostream>
using  std::cout;
using std::endl;

int count = 0;

int main()
{
    for (int i = 0; i < 10; i++)
    {
        static  int number = 0;
        for (int j = i; j < 10; j++)
        {
            number++;
            cout << number << endl;
            count++;
        }


    }


    cout << count << endl;
}

Guess you like

Origin blog.csdn.net/alexhu2010q/article/details/82023702