Re: Newbie question about <vector>
Re: Newbie question about <vector>
- Subject: Re: Newbie question about <vector>
- From: Eric Wing <email@hidden>
- Date: Wed, 5 May 2004 09:59:08 -0700 (PDT)
> From: Tristan <email@hidden>
>
> I just installed xCode, and I can't build my
> framework, wich use the
> standard c++ vector class.
>
> xCode sends me a build " vector.h : No such file or
> directory"" on
> line " #include <vector.h> "
> It works for <string.h>
>
> (same results without ".h")
>
> The problem happens only when vector is included
> from an objective-C
> class...
> It seems to compile correctly when included from a
> C++ file.
> It was working on ProjectBuilder ( with the -ObjC++
> compile flag I
> think).
The main problem is most likely that you need to make
sure your file is compiled as Objective C++, not
Objective C since <vector> belongs to C++. .m tells
Xcode that the file is Obj-C, while .mm says it's
Obj-C++. Probably renaming the extension from .m to
.mm should do the trick. You might also be able to
force the file to compile as Obj-C++ in the options
somewhere if you can't rename the file.
Also note that the C++ spec wants you to #include
<vector>, not <vector.h>. <vector.h> is provided
usually as a convenience for legacy code, before
standardization. Also keep in mind with <vector> that
you may need to fully qualify the namespace if you
aren't already.
(e.g. std::vector myvector; // notice the std:: )
A side note: be careful about what you really mean
when using <string.h> and <string>. These are two
different libraries. <string.h> is the C string
library that provides things like strcpy, strcmp, etc.
<string> is the C++ STL library that provides full
blown object-oriented strings.
/* <string.h> */
#include <string.h>
#include <stdio.h>
char* my_c_str = "C string";
char* another_c_str = "Another C string";
/* Must be extremely careful here not to overflow */
strncpy(my_c_str, another_c_str, 8);
/* should print: My C string is: C string */
printf("My C string is: %s\n", my_c_str);
// <string>
#include <string>
#include <iostream>
std::string my_cpp_string("Cpp string");
std::string another_cpp_string("Another cpp string");
// STL string is nice...overloaded = operator and
// don't have to worry about buffer overflow.
my_cpp_string = another_cpp_string;
// Should print: My Cpp string is Cpp string
std::cout << "My Cpp string is " << my_cpp_string <<
std::endl;
-Eric
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.