Forum     

Go Back   Digit Technology Discussion Forum > Software > Open Source
Register FAQ Calendar Mark Forums Read

Open Source A place where you can talk to like-minded people about the fastest growing software movement today! Discuss anything and everything about Open Source software and Operating Systems.

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 11-08-2006, 10:16 AM   #1 (permalink)
Broken In
 
Join Date: Aug 2004
Posts: 101
Default cant declare a string variable...

hello..
i've just recently begun withh c++ programming in linux, and i am using debian sarge(stable) and gcc 3.3.
my problem is that i am nor being able to use string variables, whenever i declare a string variable with
string *variablename*..
the compiler returns an error "variable string not declared".
i'd included the string.h header file..and i tried bot
#include <strings> and
#include <strings.h>

i'd searhed the g++ 3.3 include diretory and the header file is present there..but still i cant declare a string variable...

please help..
geekgod is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 11-08-2006, 10:27 AM   #2 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: cant declare a string variable...

I think it is #include <string>, not <strings>
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 11-08-2006, 11:00 AM   #3 (permalink)
Hey here is the aks
 
arunks's Avatar
 
Join Date: Jan 2006
Location: punjab
Posts: 801
Default Re: cant declare a string variable...

yes it is string.h
arunks is offline  
Old 11-08-2006, 11:28 AM   #4 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: cant declare a string variable...

If he's using g++, then saying #include <string.h> will chuck an error. Don't put the ".h", that's c-style. just say #include <string> and leave it at that.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 11-08-2006, 11:36 AM   #5 (permalink)
In The Zone
 
Venom's Avatar
 
Join Date: Jun 2006
Posts: 240
Default Re: cant declare a string variable...

He's said he tried both...
__________________
From now on we are poison to you, that's why we call ourselves, the Venom!
Venom is offline  
Old 11-08-2006, 11:40 AM   #6 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: cant declare a string variable...

He tried "strings", not "string"
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 11-08-2006, 04:12 PM   #7 (permalink)
Broken In
 
Join Date: Aug 2004
Posts: 101
Default Re: cant declare a string variable...

well i dont exactly remember whether i used <string> or <strings>..but i had used the corect one, coz i used the name of the file that was present in the include directory of g++ 3.3.
and also, i remember this much that i had used both with .h and without .h. without .h it couldnt recognise even the cout and cin functions.....which means it could recognise the declaration for iostream.h..

so..what do i do?
geekgod is offline  
Old 11-08-2006, 04:25 PM   #8 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: cant declare a string variable...

Have you included the namespace statement?
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 11-08-2006, 11:15 PM   #9 (permalink)
Broken In
 
Join Date: Aug 2004
Posts: 101
Default Re: cant declare a string variable...

@Sykora:..u mean "using namespace std"???
no..i havent..in fact i've only heard of it..never used it..what exactly does it do?
geekgod is offline  
Old 11-08-2006, 11:43 PM   #10 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: cant declare a string variable...

Ah, there's your problem.

Everything you use is defined in what is called a namespace. This is to prevent variable names clashing. All the standard C++ library resources are declared in the std namespace. If you want to use those functions, like cout, cin, etc, you must use the std namespace. otherwise, you must be writing std::cout, std::cin each time, and that's terribly time consuming.

Just insert the statement : using namespace std; somewhere at the top of your document, before you start using anything.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 11-08-2006, 11:59 PM   #11 (permalink)
Wise Old Owl
 
JGuru's Avatar
 
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
Default Re: cant declare a string variable...

It goes like this :
Code:
 
#include <string>
#include <iostream>

using namespace std;

int main()
{
       // Write what you need to do here
      // ------------
     return 0;
 }
JGuru is offline  
Old 12-08-2006, 12:12 AM   #12 (permalink)
Broken In
 
Join Date: Aug 2004
Posts: 101
Default Re: cant declare a string variable...

aha..thanx frnds..it worked.
now another problem...it is not working in windows...
giving declaration errors

if this is OT and i should post else where plz tell me so..i'll do that..

Last edited by geekgod; 12-08-2006 at 12:21 AM.
geekgod is offline  
Old 12-08-2006, 02:05 AM   #13 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: cant declare a string variable...

If you like answers reguarding windows part too in the same thread PM me. I will move it to QnA section where you will get more answers.
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 12-08-2006, 06:09 AM   #14 (permalink)
Broken In
 
Join Date: Aug 2004
Posts: 101
Default Re: cant declare a string variable...

oh no..its ok thanks..
i just posted here out of laziness in creating a new thread..:-P

and it wont be too problematic if it doesnt work in windows either...i only tried it out coz i cant make my internet work in linux and i have to reboot every time to windows i have to use the net...

thanx for ur helps guys..i guess the mods can close this thread now.
geekgod is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 01:45 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2