Welcome! Log In Create A New Profile

Advanced

String problem

Posted by KevinEvans 
String problem
July 20, 2010 09:40PM
I just woke up and I'm having a problem with strings... They don't seem to be including, even though they're included (as string.h).
Error:
main.c
/source/main.c: In function 'main':
/source/main.c:45: error: 'string' undeclared (first use in this function)
/source/main.c:45: error: (Each undeclared identifier is reported only once
/source/main.c:45: error: for each function it appears in.)
/source/main.c:45: error: expected ';' before 'dongs'

(for some reason, the >'s and the <'s are turning in to html tags :/
#include 
#include 
#include  //this is correct, right?
#include 
#include 
#include 
#include 
#include 

static u32 *xfb;
static GXRModeObj *rmode;


void Initialise() {
  
	VIDEO_Init();
	PAD_Init();
 
	rmode = VIDEO_GetPreferredMode(NULL);

	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
 
	VIDEO_Configure(rmode);
	VIDEO_SetNextFramebuffer(xfb);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
}
int main() 
{
	Initialise();
	string dongs;	//compile-time error here :(
	
	return 0;
}

Here's the makefile:
#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC)
endif

include $(DEVKITPPC)/wii_rules

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET		:=	$(notdir $(CURDIR))
BUILD		:=	build
SOURCES		:=	source
DATA		:=	data  
INCLUDES	:=	include

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------

CFLAGS	= -g -O2 -Wall $(MACHDEP) $(INCLUDE)
CXXFLAGS	=	$(CFLAGS)

LDFLAGS	=	-g $(MACHDEP) -Wl,-Map,$(notdir $@).map

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS	:=	-logc -lm

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS	:=

#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT	:=	$(CURDIR)/$(TARGET)

export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
					$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR	:=	$(CURDIR)/$(BUILD)

#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
	export LD	:=	$(CC)
else
	export LD	:=	$(CXX)
endif

export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
					$(sFILES:.s=.o) $(SFILES:.S=.o)

#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
					-I$(CURDIR)/$(BUILD) \
					-I$(LIBOGC_INC)

#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
					-L$(LIBOGC_LIB)

export OUTPUT	:=	$(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean

#---------------------------------------------------------------------------------
$(BUILD):
	@[ -d $@ ] || mkdir -p $@
	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
	@echo clean ...
	@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol

#---------------------------------------------------------------------------------
run:
	psoload $(TARGET).dol

#---------------------------------------------------------------------------------
reload:
	psoload -r $(TARGET).dol


#---------------------------------------------------------------------------------
else

DEPENDS	:=	$(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)

#---------------------------------------------------------------------------------
# This rule links in binary data with the .jpg extension
#---------------------------------------------------------------------------------
%.jpg.o	:	%.jpg
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------
# This rule links in binary data
#---------------------------------------------------------------------------------
%.bin.o	:	%.bin
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	@$(bin2o)

%.mod.o	:	%.mod
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	@$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------



Edited 3 time(s). Last edit at 07/20/2010 09:44PM by KevinEvans.
Re: String problem
July 20, 2010 10:41PM
std:string dongs;

or

using namespace std;

static u32 *xfb;
static GXRModeObj *rmode
Re: String problem
July 20, 2010 11:17PM
Didn't work ;_;
I think namespaces are in C++ only (and std is part of iostream, if i recall correctly)

Edit:
Can you use iostream with wii homebrew?



Edited 1 time(s). Last edit at 07/20/2010 11:19PM by KevinEvans.
Re: String problem
July 20, 2010 11:20PM
string is only available in C++. In C, you should use char.
Re: String problem
July 20, 2010 11:25PM
It's
char dongs[] = "dongs";
then, right? (I'm coming from a C# and Java background :/)
Re: String problem
July 20, 2010 11:37PM
If you are better in object-oriented programming, why do you code in C :)
Re: String problem
July 20, 2010 11:45PM
I'm not sure... :p
But it seems that more people use C instead of C++ for homebrew applications...
Re: String problem
July 20, 2010 11:57PM
Quote
KevinEvans
I'm not sure... :p
But it seems that more people use C instead of C++ for homebrew applications...

Not true, just the examples are C. C++ is fine to use for Wii homebrew. All my projects are C++. All you'll need to do is rename your .c files to .cpp.
Re: String problem
July 21, 2010 12:15AM
If I use C++, do I still use wiiuse/wpad.h and gcore.h? And can I use iostream instead of stdio?



Edited 1 time(s). Last edit at 07/21/2010 12:16AM by KevinEvans.
Re: String problem
July 21, 2010 12:28AM
Yes everything's the same... here's a link to one of my projects take a look as it is c++. [code.google.com]
Re: String problem
July 21, 2010 12:36AM
Ah, okay.
Thanks <3
Re: String problem
July 21, 2010 04:38AM
A category was started for homebrew done in C++.

But no one is using it :(
Re: String problem
July 21, 2010 07:37AM
Just a comment for the future, when you enter code, you can delete the > < signs from the include statements. We know you have them in there.
Re: String problem
July 21, 2010 09:23AM
Or we can start teaching people what a html entity is and how to write them :)

#include <string.h>
Re: String problem
July 21, 2010 10:35AM
"Strings" are not easy in C or even in C++. In C# and Java a lot of work is done for you, but in C/C++ you need to take care.

I suggest reading this topic: [forum.wiibrew.org] I explain a bit about 'strings' there.
Sorry, only registered users may post in this forum.

Click here to login