C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

String.h

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
LuCk
Guest





PostPosted: Thu Jan 29, 2004 2:20 am    Post subject: String.h Reply with quote



I cant seem to get any string type variables to work....I even put this
simple program together:

----------------------------------------------------------
#include <iostream.h>
#include <string.h>

int main() {
string Name;
Name = "Carl";
cout << Name << endl;
return 0;
}
----------------------------------------------------------
To test if the problem is the strings and it gives me the following errors:


--------------------Configuration: Test - Win32 Debug--------------------
Compiling...
Test.cpp
c:documents and settingsownermy documentsc++test.cpp(5) : error C2065:
'string' : undeclared identifier
c:documents and settingsownermy documentsc++test.cpp(5) : error C2146:
syntax error : missing ';' before identifier 'Name'
c:documents and settingsownermy documentsc++test.cpp(5) : error C2065:
'Name' : undeclared identifier
c:documents and settingsownermy documentsc++test.cpp(6) : error C2440:
'=' : cannot convert from 'char [5]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or
function-style cast
Error executing cl.exe.

Test.obj - 4 error(s), 0 warning(s)


Does anyone know whats going on and if its my string.h header file...can
someone give me a link to download it please.

Thankyou.

Regards,
Carl




Back to top
osmium
Guest





PostPosted: Thu Jan 29, 2004 2:27 am    Post subject: Re: String.h Reply with quote



LuCk writes:

Quote:
I cant seem to get any string type variables to work....I even put this
simple program together:

----------------------------------------------------------
#include <iostream.h
#include
int main() {
string Name;
Name = "Carl";
cout << Name << endl;
return 0;
}
snip


I think you are confusing C strings and C++ (nee STL) strings. See if your
compiler will accept

#include
You will also need a using directive.




Back to top
LuCk
Guest





PostPosted: Thu Jan 29, 2004 2:45 am    Post subject: Re: String.h Reply with quote



I tried the #include <string> in place of the #include <string.h> and it
didnt work. I still get the same exact compiler errors.

Regards,
Carl


Back to top
Cy Edmunds
Guest





PostPosted: Thu Jan 29, 2004 3:31 am    Post subject: Re: String.h Reply with quote

"LuCk" <LuCk (AT) insight (DOT) rr.com> wrote

Quote:
I tried the #include <string> in place of the #include <string.h> and it
didnt work. I still get the same exact compiler errors.

Regards,
Carl



Use std::string instead of string. Or, as osmium told you, put in a "using"
clause.

--
Cy
http://home.rochester.rr.com/cyhome/



Back to top
SenderX
Guest





PostPosted: Thu Jan 29, 2004 3:32 am    Post subject: Re: String.h Reply with quote

Quote:
#include <iostream.h
#include
int main() {
string Name;
Name = "Carl";
cout << Name << endl;
return 0;
}


#include #include <string>

int main()
{
std::string Name = "Carl";

std::cout << Name << std::endl;

return 0;
}



Back to top
Noah Roberts
Guest





PostPosted: Thu Jan 29, 2004 9:01 am    Post subject: Re: String.h Reply with quote

SenderX wrote:
Quote:
#include <iostream.h
#include
int main() {
string Name;
Name = "Carl";
cout << Name << endl;
return 0;
}



#include #include
int main()
{
std::string Name = "Carl";

std::cout << Name << std::endl;

return 0;
}



or

#include #include <iostream>

using namespace std;

int main(void)
{
string Name = "Carl";
cout << Name << endl;

return 0;
}

--
"I can't help it, the Dominating Trolls made me."


Back to top
Default User
Guest





PostPosted: Thu Jan 29, 2004 5:04 pm    Post subject: Re: String.h Reply with quote

LuCk wrote:
Quote:

I cant seem to get any string type variables to work....I even put this
simple program together:

----------------------------------------------------------
#include #include
int main() {
string Name;
Name = "Carl";
cout << Name << endl;
return 0;
}


You need to get an up-to-date book on C++ programming, one that covers
standard C++, especially the new standard library features such as
std::string.



Brian Rodenborn

Back to top
LuCk
Guest





PostPosted: Thu Jan 29, 2004 5:57 pm    Post subject: Re: String.h Reply with quote

Thanx everyone for your help!

Regards,
Carl


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.