Thread: typing effect on text

  1. #16
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    it does not run on my turbo c. i got too many errors.

  2. #17
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    And the errors say???

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    Undefined symbol 'text'
    Undefined symbol 'msg'
    Undefined symbol 'msg1'
    Extra parameter in call to TypeText()

  4. #19
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Copy and paste this to your thing

    Code:
    #include<iostream>
    #include<string>
    
    #include<windows.h> // for Sleep
    
    using namespace std; 
    
    
    /*
    #define stiring string
    // Sorry
    
    void TypeText ( stiring text ) // typo, but I'm refusing to admit it! string text
    */
    
    
    void TypeText( string text )
    {
       for ( int i=0; i<(int)text.size(); i++ )
       {
          cout<< text[i];
          Sleep( 50 );
       }
    }
    
    int main()
    {
    	string msg = "This is only a test.";
    	string msg1 = "I hope that this will work.";
    
    	TypeText ( msg );
    	TypeText ( msg1 );
    
    
    	return 0;
    
    }
    Last edited by twomers; 09-02-2006 at 09:21 AM.

  5. #20
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    void TypeText ( stiring text )
    Undefined reference to `stiring'

    Code:
    for ( int i=0; i<(int)text.size(); i++ )
    Rather than cast to an int, you could make i the same type.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #21
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Quote Originally Posted by dwks
    Code:
    void TypeText ( stiring text )
    Undefined reference to `stiring'

    Code:
    for ( int i=0; i<(int)text.size(); i++ )
    Rather than cast to an int, you could make i the same type.
    ah, i forgot the #define stiring string line. Whoops, my bad. Calling it an int, and casting is less writing, dwks

  7. #22
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yes, but it isn't much harder to use
    Code:
    for(string::size_type i; i < text.size(); i ++
    now is it?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #23
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    I agree. I use it sometimes, but I can never remember where the _ goes in it, or even if there is one there, so if I'm doing it from memory, I (cast).

    that size_type always confused me though. Why doesn't .size() just return an int?

  9. #24
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by twomers
    that size_type always confused me though. Why doesn't .size() just return an int?
    Guess it's an unsigned type because negative sizes don't make sense.
    Kurt

  10. #25
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    how come your program not work on my turbo c++? :-/

  11. #26
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Because a size_type is probably an unsigned long, but it could be bigger. I don't know about C++, but in C a size_t is the largest unsigned type supported by the compiler, even if that type is non-standard like _uint64. If you have a really long string you might need something like that.

    It's like fseek() and ftell() in C. They use int positions. Well, guess what? The C99 functions fgetpos() and fsetpos() do exactly the same thing, but using an fpos_t variable, which can hold much larger values. (Yes, there really are files larger than 2GB.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #27
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    Iterators!
    Code:
    for (string::iterator i = str.begin(); i < str.end(); i++)
    {
        cout << *i << flush;
        usleep(500000);
    }
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  13. #28
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Did you change stiring to string?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #29
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Quote Originally Posted by ZuK
    Guess it's an unsigned type because negative sizes don't make sense.
    Kurt
    Good point. But it's got its own type, right string::size_type ... I'll test out using all sorts of unsigned things tonight I think, just to see if I can get it not to warning me.

  15. #30
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Quote Originally Posted by dwks
    Did you change stiring to string?
    Yes! Just added the macros there

    painkiller05 , does it work now?
    Last edited by twomers; 09-02-2006 at 09:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text adventure engine idea. thoughts?
    By suzakugaiden in forum Game Programming
    Replies: 16
    Last Post: 01-15-2006, 05:13 AM
  2. reading from text file
    By jamez in forum C Programming
    Replies: 3
    Last Post: 11-30-2005, 07:13 PM
  3. Removing text between /* */ in a file
    By 0rion in forum C Programming
    Replies: 2
    Last Post: 04-05-2004, 08:54 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM