| Forum |
|
|||||||
| 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. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Broken In
Join Date: Aug 2004
Posts: 101
|
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.. |
|
|
| Advertisements. Register and be a member of the community to get rid of them. | |
|
Advertisement
|
|
|
|
#2 (permalink) |
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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 -- |
|
|
|
|
#4 (permalink) |
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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 -- |
|
|
|
|
#7 (permalink) |
|
Broken In
Join Date: Aug 2004
Posts: 101
|
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... so..what do i do? |
|
|
|
|
#10 (permalink) |
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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 -- |
|
|
|
|
#11 (permalink) |
|
Wise Old Owl
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
|
It goes like this :
Code:
#include <string>
#include <iostream>
using namespace std;
int main()
{
// Write what you need to do here
// ------------
return 0;
}
|
|
|
|
|
#12 (permalink) |
|
Broken In
Join Date: Aug 2004
Posts: 101
|
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. |
|
|
|
|
#13 (permalink) |
|
18 Till I Die............
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
|
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 |
|
|
|
|
#14 (permalink) |
|
Broken In
Join Date: Aug 2004
Posts: 101
|
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. |
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|