Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NSDuo

macrumors newbie
Original poster
Jan 16, 2008
18
0
I'm trying to make a simple obj loader to practice with 3D, and I thought I'd use std::string to handle text. However when I tell the compiler to #include <string> it gives me "error string: no such file or directory", weird as it only does it for this one specific project. The first place I looked was Google, and I got one result relevent to my situation and it didn't give a solution to my problem. Here is my code:

Code:
#include "global.h"
#include <string>   <------------------ the line giving me trouble, wherever I put it in the project


typedef struct vertex
{
	float x, y, z;
} vert;

typedef struct face
{
	vert points[4];
} face;

typedef struct object
{
	int noOfVerts;
	int noOfFaces;
	face *faces;
} obj;

obj *edlObj(std::string file);   <----- this line gives me "syntax error before :"
void render(obj object);
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
I'm trying to make a simple obj loader to practice with 3D, and I thought I'd use std::string to handle text. However when I tell the compiler to #include <string> it gives me "error string: no such file or directory", weird as it only does it for this one specific project. The first place I looked was Google, and I got one result relevent to my situation and it didn't give a solution to my problem. Here is my code:

Code:
#include "global.h"
#include <string>   <------------------ the line giving me trouble, wherever I put it in the project

What is the file name of your program?
 

NSDuo

macrumors newbie
Original poster
Jan 16, 2008
18
0
What is the file name of your program?

I don't exactly understand what you mean by the filename of my program. Do you mean:

my actual program? wormhole demo.app, wormhole demo.xcodeproj
the program its happening in? xcode
the file the error occurs in? edldata.h

if I'm wrong please tell me
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
I don't exactly understand what you mean by the filename of my program. Do you mean:

my actual program? wormhole demo.app, wormhole demo.xcodeproj
the program its happening in? xcode
the file the error occurs in? edldata.h

if I'm wrong please tell me

If the source file is called main.c, then XCode invokes the C compiler. And the C compiler won't find <string>, and it won't like the C++ syntax. If the source file is called main.cpp, the XCode invokes the C++ compiler which shouldn't give an error. If the source file is called main.m, then XCode invokes the Objective-C compiler; again, that won't like <string>.

Just a hint: You are starting to learn programming, and you are running into a problem. It is very, very unlikely that the problem is with XCode. It is much more likely that something that you are doing is not what you think you are doing. Like your insistence that this is a C++ program: You think it is C++. But what does the compiler think?

Add these lines:

#ifdef __cplusplus
#error Compiling C++
#else
#error Not compiling C++
#endif

and check what error you get.
 

ctaylo21

macrumors newbie
Feb 10, 2009
1
0
I had the same problem, and after I read the earlier comment I checked and sure enough i was using #include <string> in my main.c file. Oops. Switch to main.cpp and it works fine.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.