How do you declare a string in Visual C++??? 
Author Message
 How do you declare a string in Visual C++???

Every time I try to declare a string in Visual C++ it doesn't work..
Does any one know if this is a bug or something?
I have no problems using other compilers with programs that include strings.
If anyone can help, it would appreciated.

This is how I tried it:

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

void main()
{
 string some_string;

Quote:
}

--------------------------------------------------------------

...and I get these errors:

--------------------------------------------------------------
--------------------Configuration: String doesnt work - Win32
Debug--------------------
Compiling...
String doesnt work.cpp
C:\Win98\Desktop\String doesnt work.cpp(6) : error C2065: 'string' :
undeclared identifier
C:\Win98\Desktop\String doesnt work.cpp(6) : error C2146: syntax error :
missing ';' before identifier 'some_string'
C:\Win98\Desktop\String doesnt work.cpp(6) : error C2065: 'some_string' :
undeclared identifier
Error executing cl.exe.

String doesnt work.obj - 3 error(s), 0 warning(s)
--------------------------------------------------------------

Does anyone know what's wrong?

Thanks,
    Steve



Wed, 31 Jul 2002 03:00:00 GMT  
 How do you declare a string in Visual C++???

Quote:

> Every time I try to declare a string in Visual C++ it doesn't work..
> Does any one know if this is a bug or something?

Yes.  It is something and not a bug.

Quote:
> I have no problems using other compilers with programs that include strings.

The string.h file has always defined the interface
to a C library for low level C character block
management.  It has never defined any class
called "string".  So I wonder how well things
could have gone with other compilers.

Quote:
> If anyone can help, it would appreciated.

OK.  See changes below.

Quote:
> This is how I tried it:

> --------------------------------------------------------------

//// > #include <string.h>
#include <string>

//// > void main()
int main()

Quote:
> {

//// >  string some_string;
    std::string some_string;
    some_string = "I am a standard C++ string.";

Quote:
> }
> --------------------------------------------------------------

> ...and I get these errors:
[snip]
> Does anyone know what's wrong?

Get a decent C++ reference of modern
vintage, say the last several years.

--
Larry Brasfield
Above opinions may be mine alone.



Wed, 31 Jul 2002 03:00:00 GMT  
 How do you declare a string in Visual C++???


Quote:
> Every time I try to declare a string in Visual C++ it doesn't work..
> Does any one know if this is a bug or something?
> I have no problems using other compilers with programs that include strings.
> If anyone can help, it would appreciated.

> This is how I tried it:

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

Change this to:

#include <string>

Quote:
> void main()

Change this to:

int main()

Quote:
> {
>  string some_string;

And this to:

        std::string some_string;

and there should be a little partying in Mudville tonight.

--
    Later,
    Jerry.

The universe is a figment of its own imagination.



Wed, 31 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. borland C++ 5, string, XP, declaring string types

2. Visual C++ hangs when doing custom build in MFC project

3. Passing Strings from Visual C++ to Visual Basic

4. passing strings from a (Visual C++) DLL to Excel and Visual Basic

5. Passing Strings from Visual C++ to Visual Basic

6. Visual C++ .NET coexisting with Visual C++ v6.0 SP5

7. Visual C++ to eMbedded Visual C++ problem

8. Visual C++ .NET reviews, comparisons to Visual C++ 6.0

9. Do Not Install Visual C++ 5.0 Over an Installation of Visual C++ 4.x

10. Visual C++ 6.0 vs. Visual C++ .NET

11. Visual C++ .NET coexisting with Visual C++ v6.0 SP5

12. Visual C++ 6.0 contra Visual C++ Technology Preview IE4

 

 
Powered by phpBB® Forum Software