Thread: Using 'if' with char arrays or string objects

  1. #16
    Registered User
    Join Date
    May 2002
    Posts
    317
    Oh, my bad. I must have problems reading

  2. #17
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Not <string.h> for the string class, just <string>. No standard C++ headers end in .h.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #18
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    c:\program files\microsoft visual studio\myprojects\hangman\hangman.h(4) : error C2146: syntax error : missing ';' before identifier 'word'
    c:\program files\microsoft visual studio\myprojects\hangman\hangman.h(4) : error C2501: 'string' : missing storage-class or type specifiers
    c:\program files\microsoft visual studio\myprojects\hangman\hangman.h(4) : error C2501: 'word' : missing storage-class or type specifiers


    You have a missing ; and then something about "missing storage-class" (sorry, don't know about this one).

    The rest of the errors just occur because of the first ones. Fix the first error, and the other 100 will also disappear (magic ).

    Why is the struct extern? You are not linking the header file, you include it in your main program.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #19
    Registered User
    Join Date
    May 2002
    Posts
    317
    You have a missing ; and then something about "missing storage-class" (sorry, don't know about this one).
    These too are tied together for a reason. The compiler is not recognizing string as a valid type therefore it thinks that is a variable name with no type definition(storage class). The missing ; is because of how you declare variables, aka int a;char b; //ect.

  5. #20
    Registered User
    Join Date
    Apr 2002
    Posts
    48
    Thx everyone. I don't know if any of that will fix the problem yet, but I'm gonna try it out.

    As for the 'extern', I was having linking errors b4 and someone told me to use that. If I should take it out what would i do to fix the linking errors?
    Hey, you gotta start somewhere

  6. #21
    Registered User
    Join Date
    Apr 2002
    Posts
    48
    Thx everyone. I don't know if any of that will fix the problem yet, but I'm gonna try it out.

    As for the 'extern', I was having linking errors b4 and someone told me to use that. If I should take it out what would i do to fix the linking errors?
    Hey, you gotta start somewhere

  7. #22
    Registered User
    Join Date
    Apr 2002
    Posts
    48
    These are the errors i get when i take out the 'extern' and all that stuff:

    Code:
    --------------------Configuration: Hangman - Win32 Debug--------------------
    Compiling...
    Hangman.cpp
    Main.cpp
    Linking...
    Main.obj : error LNK2005: "struct hangman  hang" (?hang@@3Uhangman@@A) already defined in Hangman.obj
    Debug/Hangman.exe : fatal error LNK1169: one or more multiply defined symbols found
    Error executing link.exe.
    
    Hangman.exe - 2 error(s), 0 warning(s)
    Check out all my source code on the first page if u need any more info and once again thx a lot 4 your help even though it's all 4 a hangman game... it's a learning experience i guess you could say
    Hey, you gotta start somewhere

  8. #23
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    God....

    It turns out to be a big problem ....
    Please tell us about the resulte....

    LQQK, Please I want you to check if you realy have string.h in your lib files.... : COULD YOU PLEASE TRY TO WRITE ANOTHER SMALL PROGRAM .. AND INCLUDE STRINGS.H AND TRY TO COMPILE IT ... FOR EXAMPLE:

    Code:
    # include<iostream>;
    #include<strings.h>;
    
    int main()
    {
    string str1= " this is a string";
    cout<< str1<<endl;
    cout<< "let me know what happend.?"
    
    return 0;
    }
    If you got the same problem, that means that you have problem with your ver. of C++...
    C++
    The best

  9. #24
    Registered User
    Join Date
    Apr 2002
    Posts
    48

    !@#$!@%#(%*#%**572!@$*!@#$!@#$!@#!$%!@#$

    s***....

    From this code
    Code:
    #include<iostream>
    #include<string.h>
    
    int main()
    {
    string str1= " this is a string";
    cout<< str1<<endl;
    cout<< "let me know what happend.?"
    
    return 0;
    }
    I get these errors

    Code:
    --------------------Configuration: Testing - Win32 Debug--------------------
    Compiling...
    main.cpp
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(6) : error C2065: 'string' : undeclared identifier
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(6) : error C2146: syntax error : missing ';' before identifier 'str1'
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(6) : error C2065: 'str1' : undeclared identifier
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(6) : error C2440: '=' : cannot convert from 'char [18]' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(7) : error C2065: 'cout' : undeclared identifier
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(7) : error C2065: 'endl' : undeclared identifier
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(7) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(10) : error C2297: '<<' : illegal, right operand has type 'char [27]'
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(10) : error C2143: syntax error : missing ';' before 'return'
    Error executing cl.exe.
    
    Testing.exe - 8 error(s), 1 warning(s)
    wtf is wrong?
    Hey, you gotta start somewhere

  10. #25
    Registered User
    Join Date
    Apr 2002
    Posts
    48
    btw i don't know if i mentioned it but i have visual c++ 6.0
    Hey, you gotta start somewhere

  11. #26
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Question let me test it ....

    I will try to test it right now and I will tell you what is going onnnnnnnnnnnn


    hmmmmmmmmmmmmmmm..............
    C++
    The best

  12. #27
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    The code is ready

    Try this now...

    Code:
    #include<iostream.h>
    #include<string>
    
    int main()
    {
    string str1= " this is a string";
    cout<< str1<<endl;
    cout<< "let me know what happend.?";
    
    return 0;
    }
    I hope you got something out of it.
    C++
    The best

  13. #28
    Registered User
    Join Date
    Apr 2002
    Posts
    48
    nope... same thing.

    The strings used to work, so how come they don't work anymore?
    Hey, you gotta start somewhere

  14. #29
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    What do you mean by that

    Does it work or it doesn;t


    I could'nt understand...
    if not please post your error message...
    C++
    The best

  15. #30
    Registered User
    Join Date
    Apr 2002
    Posts
    48
    it doesn't work

    it gives me pretty much the same errors as b4.

    it has no idea what a string is for some reason.

    how can i fix this problem?
    Hey, you gotta start somewhere

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  2. Passing pointers to arrays of char arrays
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 03-31-2006, 05:31 AM
  3. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM