string undeclared ?

This is a discussion on string undeclared ? within the C++ Programming forums, part of the General Programming Boards category; Code: I have got some truble,like these: dream@liuguobiao:~/Desktop$ cat c.c #include <stdio.h> #include <string.h> int main() { string st; st ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Location
    China Guangzhou
    Posts
    7

    Unhappy string undeclared ?

    Code:
    I have got some truble,like these:
    
    dream@liuguobiao:~/Desktop$ cat c.c
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
            string st;
            st = Getline();
            return 0;
    }
    dream@liuguobiao:~/Desktop$ gcc -o c c.c
    c.c: In function 'main':
    c.c:6: error: 'string' undeclared (first use in this function)
    c.c:6: error: (Each undeclared identifier is reported only once
    c.c:6: error: for each function it appears in.)
    c.c:6: error: expected ';' before 'st'
    c.c:7: error: 'st' undeclared (first use in this function)
    dream@liuguobiao:~/Desktop$ 
    
    why it said "string undeclared" ?
     I can find "string.h"  in  "/usr/include" 
     but why i can't use 'string' declared the 'st'  ?
     help me ......

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    There is no data type in C called "string". (There is in C++, if that's what you meant to use.)

  3. #3
    Registered User
    Join Date
    Feb 2009
    Location
    China Guangzhou
    Posts
    7
    Code:
    I am chage the code to :
    #include <iostream>
    #include <string>
    useing namespace std;
    int main()
    {
            string st;
            return 0;
    }
    but it return :
    c.cpp:3: error: expected constructor, destructor, or type conversion before 'namespace'
    c.cpp: In function 'int main()':
    c.cpp:6: error: 'string' was not declared in this scope
    c.cpp:6: error: expected `;' before 'st'
    I don't understand ,can you help me?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You should spell "using" appropriately.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Location
    China Guangzhou
    Posts
    7
    OH ! I am sorry . It run ! Thanks !!
    I using the Getline(),it said 'Getline' was not declared in this scope.
    can you tell me Getline() in which head file ? Not "string.h" ?
    Last edited by liuguobiao; 02-20-2009 at 10:40 PM.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,118
    The function is named getline, not Getline.

    *Moved to C++ programming forum*
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Feb 2009
    Location
    China Guangzhou
    Posts
    7
    Thanks very much !laserlight .
    I will study hardly in it .
    Thanks !!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 10:15 PM
  2. Brand new to C need favor
    By dontknowc in forum C Programming
    Replies: 5
    Last Post: 09-21-2007, 11:08 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 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, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21