CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    40

    cin >> buf endless loop

    Hi

    I have the code

    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
    	string buf;
    
    	while( cin >> buf )
    	{
    		cout << buf;
    
    		//do some process in buf
    	}
    	//end the loop someway
    
    	cout << "The result";
    
    	return 0;
    }

    With what keyboard shortcut I can end the loop in order to proceed in my program ( I am not interested in signal solution or

    Code:
     
    if ( buf == "END" )
    break;
    Thanks

  2. #2
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: cin >> buf endless loop

    You can send the EOF character with CONTROL+Z, but it may behaves strangely (and need two CTRL+Z in some cases).
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

  3. #3
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658

    Re: cin >> buf endless loop

    I believe ctrl+c or ctrl+d, and look for the .fail() function check the fail bit. I can't remember for sure, though, sorry.
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

  4. #4
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: cin >> buf endless loop

    CTRL+C terminates the process, with memory leaks and all the bad effects.
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured