Thread: String Help

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    3

    Question String Help

    Hey everyone,

    This is my first post so go easy on me. I am pretty much a beginner when it comes to C++ so please assume that I know nothing when you reply

    Okay so here is the question, I am trying to create a simple function using Dev C++
    for a dos base program.

    Basically what I want the function to end up with is when I type something similar to typeit("This is my text"); it will display the characters on the screen one by one (like on the matrix).

    I thought I had this worked out and when I compile the prog I get truckloads or errors..javascript:smilie('')
    confused Can you guys please look at the code below and let me know what I am doing wrong (in english)


    void typeit(string type_text){

    double x= type_text.size();
    char ticker[x]=type_text;

    double i=0

    while (i != x/4){wait(.3); cout ticker[x];i++;}

    while (i != x/4*2){wait(.2); cout ticker[x];i++;}

    while (i != x/4*3){wait(.1); cout ticker[x];i++;}

    while (i != x){wait(.2); cout ticker[x];i++;}

    wait(2);

    system("cls");

    }

    Any suggestions

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    552

    Thumbs up

    >double x= type_text.size();
    >char ticker[x]=type_text;

    Why are you declaring x as type double? an int would be better. Also, im not sure if you can declare an array size with a doube value, although the compiler will probably do a typecast automatically.

    Im not too familiar with the string class but I think how you initialized ticker is invalid. Why not just use your 'type_text' variable in place of your ticker.

    >double i=0
    something's missing;;;

    >if (i != x/4)
    well, this is no good. since 'i' will only be a whole number and x/4 could evaluate to a fraction, you will need to use '>' or '<' instead of '!='

    >cout ticker[x];
    should be cout << ticker[x];
    check the syntax of the cin/cout objects

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    3
    Thanks clownpimp some of those errors were stupid typos and cleared up alot of compiler errors but the main problem was the string not being recognised by the compiler

    ie typeit(string type_text)
    and type_text.size();

    And yes I have included string.h, so what can I do to fix this...?

    The errors are sayin stuff like string undeclared and type_text undeclared...........

    Other suggestions....

  4. #4
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    What compiler are you using? Instead of including string.h include string like the following:
    Code:
    #include<string>
    using std::string;
    string.h is the old C-style string header, while string is the new standard header, and to recognize the string class you must either use the using std::string, using namespace std, or qualify each declaration of a string with std::string string_name;
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    3
    with a bit of fiddling around I have got it to work thanks so much for all your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM