none
cin in while loop.

    Question

  • what is the problem in using

    while(cin>><some variable here>) {

    }

    kind of syntax?

    Visual studios considering it as error and shows red line under >> operator.

    However the code runs properly with other editors/ compilers. like Code Blocks, etc.

    Any help?

    Wednesday, July 13, 2016 12:01 AM

Answers

  • Hi AdnurakYi,

    Please try this:

    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int I;
    	while (cin >>I) {
    
    	}
    	/*int i;
    	cout << "Please enter an integer value: ";
    	cin >> i;*/
    	
    	return 0;
    } 

    Best Regards,

    Lake Xiao

    Wednesday, July 13, 2016 2:54 AM
    Moderator

All replies

  • Did you forget to add:

    using namespace std;

    ??

    Wednesday, July 13, 2016 2:36 AM
  • Hi AdnurakYi,

    Please try this:

    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int I;
    	while (cin >>I) {
    
    	}
    	/*int i;
    	cout << "Please enter an integer value: ";
    	cin >> i;*/
    	
    	return 0;
    } 

    Best Regards,

    Lake Xiao

    Wednesday, July 13, 2016 2:54 AM
    Moderator
  • Please include the error message. Usually when you get an error message, it is necessary to provide the message in the question.


    Sam Hobbs
    SimpleSamples.Info

    Wednesday, July 13, 2016 3:52 AM