| Water Fountain General Chit/Chat |
|
05-10-05, 05:33 PM
|
#1 (permalink)
|
|
Guest
|
c++ acting retarded
Ok, all i want to do is display a "......." like a loading thing, so cout a ".", then pause, then cout another one, etc. Nothing too exciting or hard.
So i tried the simpliest way to pause, by using a blank forloop, but for simplicity i will just show the pause with the windows.h.
for (int x=0;x<=8;x++)
{
cout<<".";
Sleep(1000);
}
should display a ".", then sleep, then display a ".", right?
But it doesnt!!! It pauses a log time, then displays the 8 "."'s. SO then i just tried
cout<<"asdf"<<endl;
Sleep(1000);
and instead of dispaling asdf THEN pausing, it pauses FIRST! WTF?
|
|
|
|
|
05-10-05, 06:57 PM
|
#2 (permalink)
|
|
Aximsite Minor League
Join Date: Jan 2004
Location: Somewhere
Posts: 110
Device: Some crappy LG
Carrier: Verizon
Thanked 0 Times in 0 Posts
|
Give me a larger chunk of your code.
__________________
-GWing_02
http://colonyl2.ath.cx/
|
|
|
|
05-10-05, 07:01 PM
|
#3 (permalink)
|
|
Aximsite Rookie
DAP Freshman
Join Date: Nov 2004
Location: Syracuse, NY
Posts: 84
Thanked 0 Times in 0 Posts
|
yea, a larger section of code would make it easier to look at. Also, is this for PPC or for PC Windows?
here is a sample piece of code that does what you were talking about.
|
Code:
|
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
void main (void)
{
for(int i = 0; i < 8; i++)
{
cout << ".";
for(int j = 0; j < 30000000; j++);
}
} |
i hope this is what you were looking for. The dots go by pretty fast, but you can change the loop count. I don't know if all the libraries are needed, but thats cause i haven't programed in C++ in about a year.
Last edited by sdpinter; 05-10-05 at 07:16 PM.
|
|
|
|
05-10-05, 07:20 PM
|
#4 (permalink)
|
|
Guest
|
Your code works. What did i do wrong with mine? *sigh*
Last edited by schrags11; 05-10-05 at 07:27 PM.
|
|
|
|
|
05-10-05, 07:27 PM
|
#5 (permalink)
|
|
Aximsite Rookie
DAP Freshman
Join Date: Nov 2004
Location: Syracuse, NY
Posts: 84
Thanked 0 Times in 0 Posts
|
well, from looking at the version you have online, i don't see anything wrong. there is the possibility that you accidentally typed sometihng wrong previously.
I never really used sleep in my C++ code as most of it was designed for high speed sorting/searching so i'm not sure about this, but it might have caused the program to sleep before the video had a chance to draw the "." this is of course a guess, but i'd have to play with it to be sure.
also on 1 last note, you have (int x=0; x <=8; x++) just a reminder that that will print 9, not 8 "." :-D its easy to mix up but for this case i guess it doesn't really matter.
|
|
|
|
05-10-05, 07:30 PM
|
#6 (permalink)
|
|
Guest
|
I just simply had
|
Code:
|
#include <iostream.h>
void main()
{
for (int x=1;x<=8;x++)
{
cout<<".";
for (int i=1;i<=5000000000;i++);
}
} |
Which i dont see why it wouldnt work. (be patient with me, lol. :approve: )
Last edited by schrags11; 05-10-05 at 07:38 PM.
|
|
|
|
|
05-10-05, 07:43 PM
|
#7 (permalink)
|
|
Aximsite Rookie
DAP Freshman
Join Date: Nov 2004
Location: Syracuse, NY
Posts: 84
Thanked 0 Times in 0 Posts
|
well, with that code ther you have 5,000,000,000 > 2^32 == 4,294,967,296. a signed int is a 32 bit structure so your max value for it will be 2^16 (since the other half are negative). so your condition will never be true. so on my computer (compiled with VS 2003 .NET) it never reaches that wonderful limit  and just loops forever. I think if its compiled with VS 6.0 it acts different but i can't remember.
|
|
|
|
05-10-05, 07:52 PM
|
#8 (permalink)
|
|
Guest
|
Yeah im using 6.0, and still does it with a smaller int. So did it work right compiled in 03?
Last edited by schrags11; 05-10-05 at 07:57 PM.
|
|
|
|
|
05-10-05, 08:11 PM
|
#9 (permalink)
|
|
Aximsite Prospect
DAP Rookie
Join Date: Apr 2005
Posts: 5
Thanked 0 Times in 0 Posts
|
try flush()ing your output
Have you actually tried flushing the output? Generally, the OS will store output commands and "flush" them (do the actual output) at some point when it's convenient. So, your periods are probably just getting queued up someplace. You can, however, force the OS to flush your output channel by calling flush().
In C, you'd do something like:
printf(".");
flush(stdout);
In C++, it looks like you could (I haven't tried it--Stroustrup 3rd Ed. claims it works):
cout << "." << flush;
or:
cout << "."; cout.flush();
See if that helps.
|
|
|
|
05-10-05, 08:50 PM
|
#10 (permalink)
|
|
Guest
|
|
Originally Posted by happymonkey
|
Have you actually tried flushing the output? Generally, the OS will store output commands and "flush" them (do the actual output) at some point when it's convenient. So, your periods are probably just getting queued up someplace. You can, however, force the OS to flush your output channel by calling flush().
In C, you'd do something like:
printf(".");
flush(stdout);
In C++, it looks like you could (I haven't tried it--Stroustrup 3rd Ed. claims it works):
cout << "." << flush;
or:
cout << "."; cout.flush();
See if that helps.
|
cout << "." << flush; works!!!!
Thanks all!
|
|
|
|
|
05-10-05, 08:52 PM
|
#11 (permalink)
|
|
Aximsite Prospect
DAP Rookie
Join Date: Apr 2005
Posts: 5
Thanked 0 Times in 0 Posts
|
|
Originally Posted by sdpinter
|
well, with that code ther you have 5,000,000,000 > 2^32 == 4,294,967,296. a signed int is a 32 bit structure so your max value for it will be 2^16 (since the other half are negative). so your condition will never be true. so on my computer (compiled with VS 2003 .NET) it never reaches that wonderful limit and just loops forever. I think if its compiled with VS 6.0 it acts different but i can't remember.
|
If the basic int is 32 bits, then a signed int would have a magniture of 31 bits (in each positive and negative direction).
The only other thing I might add is that using Sleep() might be better than an inlined loop for the sake of your PDA's battery. Sleep() would presumably let the OS do something with the time you're giving it (such as slow theprocessor speed or whatever they do to lengthen your battery life). A tight for-loop would probably just burn more CPU cycles and hence more battery.
|
|
|
|
05-10-05, 09:19 PM
|
#12 (permalink)
|
|
Aximsite Rookie
DAP Freshman
Join Date: Nov 2004
Location: Syracuse, NY
Posts: 84
Thanked 0 Times in 0 Posts
|
|
Originally Posted by happymonkey
|
If the basic int is 32 bits, then a signed int would have a magniture of 31 bits (in each positive and negative direction).
The only other thing I might add is that using Sleep() might be better than an inlined loop for the sake of your PDA's battery. Sleep() would presumably let the OS do something with the time you're giving it (such as slow theprocessor speed or whatever they do to lengthen your battery life). A tight for-loop would probably just burn more CPU cycles and hence more battery.
|
yea  wasn't thinking
|
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:59 PM.
Powered by vBulletin® Version 3.8.2 Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Copyright © 2003-09 LeckMedia, LLC
|
| |