why is the flag being set to fail

This is a discussion on why is the flag being set to fail within the C++ Programming forums, part of the General Programming Boards category; after the second input it seems like the fail flag is set and it wont accept input the next time ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    71

    why is the flag being set to fail

    after the second input it seems like the fail flag is set and it wont accept input the next time

    here is the code.. really small and simple program

    Code:
    #include <iostream>
    #include <conio.h>
    #include <cstring>
    using namespace std;
    
    int main (void)
    {
    	int x = 0;
    	char *f1,*f2,*f3;
    	char f1f[20],f2f[100];
    	cout << "Enter the number of loops: ";
    	cin >> x;
    	cout << "Enter the Computer Name: ";
    	cin >> f1f;
    	cout << "Type in the message you wanna send: ";	
    	cin.getline (f2f, sizeof (f2f),'\n');
    	f1 = new char [strlen(f1f)+1];
    	strcpy (f1, f1f);
    	f2 = new char [strlen(f2f)+1];
    	strcpy (f2, f2f);
    	f3 = new char [11+strlen(f1)+strlen(f2)];
    	strcpy (f3, "net send ");
    	strcat (f3, f1);
    	strcat (f3, " ");
    	strcat (f3, f2);
    	for (int i = 0; i < x; i++)
    		system (f3);
    	return 0;
    }
    cheers
    Last edited by mackol; 04-17-2003 at 05:36 PM.

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    Code:
    	cout <<flush<< "Enter the Computer Name: ";

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    71
    actually when i added a cin.ignore () it did the job too

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    mackol,

    If you don't already know and want to understand why you need to add cin.ignore(), click on number 4 here:

    http://www.augustcouncil.com/~tgibso...al/iotips.html
    Last edited by 7stud; 04-18-2003 at 01:36 AM.

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    71
    Originally posted by 7stud
    mackol,

    If don't already know and want to understand why you need to add cin.ignore(), click on number 4 here:

    http://www.augustcouncil.com/~tgibso...al/iotips.html
    that was an excellent explanation mate
    i totally understand now
    thanks a lot mate

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  2. C help for network animator
    By fastshadow in forum Tech Board
    Replies: 7
    Last Post: 03-17-2006, 02:44 AM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. Set fail flag in istream
    By *ClownPimp* in forum C++ Programming
    Replies: 0
    Last Post: 03-20-2003, 08:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21