Results 1 to 18 of 18

Thread: whats wrong here

  1. #1

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919

    Unhappy whats wrong here

    im trying out CString, just experimenting, and im going crazy. i've look at a couple of sites, and it's correct:

    Code:
    #include <cstring.h>
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    void main(void){
    	CString s1;
    
    	s1= "hello";
    
    	printf("%s",s1.Right(1));
    }
    The Errors:

    --------------------Configuration: Cpp1 - Win32 Debug--------------------
    Compiling...
    Cpp1.cpp
    C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(7) : error C2065: 'CString' : undeclared identifier
    C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(7) : error C2146: syntax error : missing ';' before identifier 's1'
    C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(7) : error C2065: 's1' : undeclared identifier
    C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(8) : error C2146: syntax error : missing ';' before identifier 's2'
    C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(8) : error C2065: 's2' : undeclared identifier
    C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(8) : error C2228: left of '.Right' must have class/struct/union type
    Error executing cl.exe.

    Cpp1.exe - 6 error(s), 0 warning(s)

    im going crazy over this!

    then i tried converting to pointers, and still the same errors
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Try declaring the included file as:

    VB Code:
    1. #include <cstring>
    2. #include <string>
    3. #include <stdio.h>
    4. #include <stdlib.h>
    Baaaaaaaaah

  3. #3

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    still the same errors..

    i think vc++ is on crack
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  4. #4
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    I don't think you can printf a CString.

    printf() is meant for null terminated strings.

    Meanwhile I am looking the MSDN docs for you.
    I'm a VB6 beginner.

  5. #5

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    thanks man,


    i dont think thats the problem though., it says its missing a ';', when it isnt...and it says the vars aren't defined
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  6. #6
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    You can use CString only in a MFC app.

    I think you can only use null terminated strings. I don't think string class in #include<string> provide extracting strings from a string. You got to do it(the extracting) yourself

    Meanwhile you can wait patiently for someone to help.

    Me no string expert.

  7. #7

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    only in an MFC app? darn...i dont know MFC yet...gotta start learnin more

    --thanks for the help
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I think you can use CString in console apps by creating a "console app that supports MFC" (in the VC++ wizard). This will add a lot of overhead though.
    To use it with printf you would need to explicitely cast to LPCTSTR:
    Code:
    CString str("Hello, World!");
    printf("%s", (LPCTSTR)str.Right(1));
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    yeah i made one that supports MFC and it worked.


    ill try that other thingy later..mmm food

    thanks
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    If you want to get a substring out of a C++ string, then use the .substr(...) method:
    Code:
    #include <iostream>
    #include <string>
    
    int main() {
        string x = "Hello there!";
    
        cout << x.substr(x.length() - 1, 1) << endl;
    
        return 0;
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    okiedokie..

    i like my CString..it has the Left(), Right() and Mid() funcstions to make to happy
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You can synthesise Left and Right simply enough, and Mid == substr

    Anyway, why use CString when you can easily use string, and then you've got full standard library compatibility? For example, you can't do this with a CString:
    Code:
    cout << my_c_string << endl;
    ...without writing your own inserter.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  13. #13

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    do u have any tutorials? i'm willing to learn it...

    thanks
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What's to learn?
    Code:
    string x = "Hello";
    
    string y = x + " " + "World!";
    
    string z = string("This ") + x + " is an example";
    For z, note that the first This needs to be inside a string constructor, otherwise when the compiler resolves the right hand side it tries to add two pointers together, which is illegal. Forcing it into a string makes it all resolve properly

    And then you've got .substr, which is like Mid().

    There's no "Format" like with CString, but you can synthesise it easily enough using vsnprintf. I don't have the code at work, but when I get home if you've replied by then I can send it.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  15. #15

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    well the string things i needed/wanted were like "Left", and "Right"
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    That's my point, they're simply applications of Mid or substr.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  17. #17

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    i was wondering though,

    is there a tutorial? im playing around with string.h now..
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  18. #18
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Ah. string.h != string.

    string.h contains the C string handling functions, which you're likely to need a tutorial for (or just look at the MSVC docs). string has the C++ Standard Library's string class, and that's pretty easy to use.

    Actually, the MSVC docs have info on the string class as well - they tell you everything you need to know.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

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



Click Here to Expand Forum to Full Width