[C++] - strange things:(-VBForums
Results 1 to 7 of 7

Thread: [C++] - strange things:(

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,915

    [C++] - strange things:(

    Code:
    int main()
    {	
    	char name[255];
    	while (name !="exit")
    	{
    		std::cout<< "Insert your name:\n";
    		std::cin>>name;
    		std::cout<< "Hi "<<name<<"\n";
    		std::cin>>name;	
    		std::cout<<name;
    	}
    	return 0;
    }
    why these code takes very time to open the exe?
    why when i type "exit", the program don't close it?
    (only with me these stupid errors)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,013

    Re: [C++] - strange things:(

    Comparing name and "exit" will only compare the pointers, there will be no string comparison. Take a look at strcmp
    ---My Flickr photo (mostly screenshots these days!) stream. Have a look!

    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    TCP client/server connection | Retrieving the EventHandler for any Event by code.
    Check out the work in progress: Vortex - C++ 3D Game engine for windows and linux - (Development blog - Leave a comment!)

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,915

    Re: [C++] - strange things:(

    Quote Originally Posted by Atheist View Post
    Comparing name and "exit" will only compare the pointers, there will be no string comparison. Take a look at strcmp
    still not working
    Code:
    #include <iostream.h>
    #include <string.h>
    
    int main()
    {
    	char name[255];
    	do
    	{	
    		cout<< "Insert your name:\n";
    		cin>>name;
    		cout<< "Hi "<<name<<"\n";
    		cin>>name;	
    	} 
    	while (strcmp (name, "exit")==false);
    	
    	return 0;
    }
    anotherthing: now the 'std::' was give me an error, that's why i delete... strange
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,915

    Re: [C++] - strange things:(

    ok.. now works fine;
    Code:
    #include <iostream.h>
    #include <string.h>
    #include <stdlib.h>
    
    int main()
    {
    	char name[255];	
    	do
    	{	
    		system("cls");
    		cout<< "Insert your name:\n";
    		cin>>name;
    		cout<< "Hi "<<name<<"\n";	
    		cin>>name;		
    	}
    	while (strcmp (name, "exit")!=0);	
    	return 0;
    }
    but why takes time to open(in IDE: Visual C ++ 6))?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,013

    Re: [C++] - strange things:(

    Do you mean it takes a long period of time to open the project, or to run the project?
    If it is the latter, I would suggest you look in the output-window of the build process. What is happening when its being slow?
    ---My Flickr photo (mostly screenshots these days!) stream. Have a look!

    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    TCP client/server connection | Retrieving the EventHandler for any Event by code.
    Check out the work in progress: Vortex - C++ 3D Game engine for windows and linux - (Development blog - Leave a comment!)

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,915

    Re: [C++] - strange things:(

    Quote Originally Posted by Atheist View Post
    Do you mean it takes a long period of time to open the project, or to run the project?
    If it is the latter, I would suggest you look in the output-window of the build process. What is happening when its being slow?
    when i change the code and click in '!'(build command), the IDE takes very time to open the new exe. but after these, if i click again, don't happens
    is about being windows 7?
    (the output-window seems ok. after saying 'Linking...', it takes 1 minute or 2 for open the exe)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,915

    Re: [C++] - strange things:(

    anotherthing: if i do these(take off the loop):
    Code:
    #include <iostream>
    #include <string.h>
    #include <stdlib.h>
    using namespace std;
    
    int  main()
    {
    	char name[255];
    	//do
    	//{
    		system("cls");
    		cout<<"Insert your name.\n";
    		cin>> name;
    		cout<< "Your name is: " << name << "\n";
    		cin>>name;
    	//}
    	//while(strcmp(name,"exit")!=0) ;
    	return 0;
    }
    the program executes(in IDE) much more faster(normal speed).
    so??? it's my system(windows 7 for the Visual C++6) or otherthing?
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.