it does not run on my turbo c. i got too many errors.
Printable View
it does not run on my turbo c. i got too many errors.
And the errors say???
Undefined symbol 'text'
Undefined symbol 'msg'
Undefined symbol 'msg1'
Extra parameter in call to TypeText()
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;
}
Undefined reference to `stiring' :DCode:void TypeText ( stiring text )
Rather than cast to an int, you could make i the same type.Code:for ( int i=0; i<(int)text.size(); i++ )
ah, i forgot the #define stiring string line. Whoops, my bad. Calling it an int, and casting is less writing, dwks :)Quote:
Originally Posted by dwks
Yes, but it isn't much harder to use
now is it?Code:for(string::size_type i; i < text.size(); i ++
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?
Guess it's an unsigned type because negative sizes don't make sense.Quote:
Originally Posted by twomers
Kurt
how come your program not work on my turbo c++? :-/
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.)
Iterators!
Code:for (string::iterator i = str.begin(); i < str.end(); i++)
{
cout << *i << flush;
usleep(500000);
}
Did you change stiring to string?
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.Quote:
Originally Posted by ZuK
Yes! Just added the macros thereQuote:
Originally Posted by dwks
painkiller05 , does it work now?