Thread: string undeclared ?

  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,336
    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,336
    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
    28,413
    The function is named getline, not Getline.

    *Moved to C++ programming forum*
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 09:15 PM
  2. Brand new to C need favor
    By dontknowc in forum C Programming
    Replies: 5
    Last Post: 09-21-2007, 10: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, 06:49 PM