[Solved] String and Vector woes

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
keyz182
Posts: 2
Joined: Fri May 23, 2008 11:50 pm

[Solved] String and Vector woes

Post by keyz182 »

I've recently been moving from java to c/c++ and decided to try it on't psp. At the moment i'm messing with file operations and such, and am simply trying to read all the mp3 file paths into a vector of strings. However, when I compile I get some somewhat incomprehensible errors. I did find one similar situation, but the answer given there didnt work and that was to add the "-lstdc++" lib to the Makefile.

Source:

Code: Select all

#include <pspdisplay.h>
#include <pspctrl.h> 
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <pspiofilemgr.h>
#include <pspiofilemgr_stat.h>
#include <pspiofilemgr_dirent.h>
#include <vector>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include "songlist.cpp"

PSP_MODULE_INFO&#40;"Files", 0, 1, 1&#41;; 
using namespace std;


vector<string> slist;

//#define printf pspDebugScreenPrintf 

//There be dragons here&#58;
/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
          sceKernelExitGame&#40;&#41;;
          return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
          int cbid;

          cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, 
NULL&#41;;
          sceKernelRegisterExitCallback&#40;cbid&#41;;

          sceKernelSleepThreadCB&#40;&#41;;

          return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
          int thid = 0;

          thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 
0x11, 0xFA0, 0, 0&#41;;
          if&#40;thid >= 0&#41; &#123;
                    sceKernelStartThread&#40;thid, 0, 0&#41;;
          &#125;

          return thid;
&#125; 

void getList&#40;char *path&#41;&#123;
	char newPath&#91;80&#93;;
	SceUID fd = sceIoDopen&#40;path&#41;;
	if &#40;fd >= 0&#41; &#123;
		char *curdir;
   		for &#40;;;&#41; &#123;
      			struct SceIoDirent entry;
      			memset&#40;&entry, 0, sizeof&#40;struct SceIoDirent&#41;&#41;;
      			if &#40;sceIoDread&#40;fd, &entry&#41; <= 0&#41;
         			break;
			if &#40;&#40;entry.d_stat.st_mode&FIO_S_IFDIR&#41;==FIO_S_IFDIR&#41; &#123;
				if&#40;!strcmp&#40;entry.d_name,"."&#41; || !strcmp&#40;entry.d_name,".."&#41;&#41;&#123;
					
				&#125; else &#123;
					//printf&#40;"%s &#91;DIR&#93;\n", entry.d_name&#41;;
					sprintf&#40;newPath, "%s%s", path,entry.d_name&#41;;
					//printf&#40;"  ==>  %s\n",newPath&#41;;
					getList&#40;newPath&#41;;
					
					sprintf&#40;curdir,"%s",newPath&#41;;
				&#125;				
			&#125; else &#123;	
				string tmp&#40;entry.d_name&#41;;
				//sprintf&#40;tmp,"%s", entry.d_name&#41;;
				slist.push_back&#40;tmp&#41;;
				//printf&#40;"%s &#91;FILE&#93;\n", entry.d_name&#41;;
				//a->insertBack&#40;0,*entry.d_name&#41;;
				
			&#125;
   		&#125;
	&#125;
	sceIoDclose&#40;fd&#41;;
&#125;

int main &#40;&#41; &#123;
	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;
	char file&#91;40&#93; = "ms0&#58;/MUSIC/";
	getList&#40;file&#41;;
	/*song tmp;
	for&#40;int i = 0; i < list.size&#40;&#41;; i++&#41;&#123;
		tmp = list.at&#40;i&#41;;
		printf&#40;"%s\n",tmp.path&#41;;
	&#125;*/
	sceKernelSleepThread&#40;&#41;;
	return 0;
&#125;
Log:

Code: Select all

make -k 
psp-g++ -I.. -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I.. -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=390    -c -o main.o main.cpp
main.cpp&#58; In function ‘void getList&#40;char*&#41;’&#58;
main.cpp&#58;81&#58; error&#58; variable ‘std&#58;&#58;string tmp’ has initializer but incomplete type
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_vector.h&#58; In destructor ‘std&#58;&#58;_Vector_base<_Tp, _Alloc>&#58;&#58;~_Vector_base&#40;&#41; &#91;with _Tp = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >, _Alloc = std&#58;&#58;allocator<std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> > >&#93;’&#58;
mksfo 'File Manipulation' PARAM.SFO
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_vector.h&#58;203&#58;   instantiated from ‘std&#58;&#58;vector<_Tp, _Alloc>&#58;&#58;vector&#40;const _Alloc&&#41; &#91;with _Tp = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >, _Alloc = std&#58;&#58;allocator<std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> > >&#93;’
main.cpp&#58;22&#58;   instantiated from here
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_vector.h&#58;119&#58; error&#58; invalid use of undefined type ‘struct std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stringfwd.h&#58;56&#58; error&#58; declaration of ‘struct std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h&#58; In function ‘void std&#58;&#58;__destroy_aux&#40;_ForwardIterator, _ForwardIterator, __false_type&#41; &#91;with _ForwardIterator = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >*&#93;’&#58;
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h&#58;155&#58;   instantiated from ‘void std&#58;&#58;_Destroy&#40;_ForwardIterator, _ForwardIterator&#41; &#91;with _ForwardIterator = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >*&#93;’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h&#58;182&#58;   instantiated from ‘void std&#58;&#58;_Destroy&#40;_ForwardIterator, _ForwardIterator, std&#58;&#58;allocator<_T2>&#41; &#91;with _ForwardIterator = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >*, _Tp = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >&#93;’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_vector.h&#58;272&#58;   instantiated from ‘std&#58;&#58;vector<_Tp, _Alloc>&#58;&#58;~vector&#40;&#41; &#91;with _Tp = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >, _Alloc = std&#58;&#58;allocator<std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> > >&#93;’
main.cpp&#58;22&#58;   instantiated from here
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h&#58;121&#58; error&#58; cannot increment a pointer to incomplete type ‘std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h&#58; In function ‘void std&#58;&#58;_Destroy&#40;_Tp*&#41; &#91;with _Tp = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >&#93;’&#58;
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h&#58;122&#58;   instantiated from ‘void std&#58;&#58;__destroy_aux&#40;_ForwardIterator, _ForwardIterator, __false_type&#41; &#91;with _ForwardIterator = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >*&#93;’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h&#58;155&#58;   instantiated from ‘void std&#58;&#58;_Destroy&#40;_ForwardIterator, _ForwardIterator&#41; &#91;with _ForwardIterator = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >*&#93;’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h&#58;182&#58;   instantiated from ‘void std&#58;&#58;_Destroy&#40;_ForwardIterator, _ForwardIterator, std&#58;&#58;allocator<_T2>&#41; &#91;with _ForwardIterator = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >*, _Tp = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >&#93;’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_vector.h&#58;272&#58;   instantiated from ‘std&#58;&#58;vector<_Tp, _Alloc>&#58;&#58;~vector&#40;&#41; &#91;with _Tp = std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >, _Alloc = std&#58;&#58;allocator<std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> > >&#93;’
main.cpp&#58;22&#58;   instantiated from here
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h&#58;107&#58; error&#58; invalid use of undefined type ‘struct std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stringfwd.h&#58;56&#58; error&#58; declaration of ‘struct std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> >’
make&#58; *** &#91;main.o&#93; Error 1
make&#58; Target `all' not remade because of errors.
Thanks for any help, I've spent the last day or so hunting for soloutions, each one leading to another error :(
Last edited by keyz182 on Sat May 24, 2008 11:53 pm, edited 1 time in total.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Probably the first error is because you forgot to "#include <string>" or similar. This forum is not here to help teach people C++, so you won't find much help.
keyz182
Posts: 2
Joined: Fri May 23, 2008 11:50 pm

Post by keyz182 »

thanks, I was advised to change #include <string> to #include <string.h> seems changing it back did the trick
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

keyz182 wrote:thanks, I was advised to change #include <string> to #include <string.h> seems changing it back did the trick
<string> and <string.h> are totally different beasts :

1) <string.h> or <cstring> gives you standard functions like strlen, strcat, and so on

2) <string> gives you std::string

just remind it : STL headers don't have a ".h" suffix.

<vector> ==> std::vector<...>
<map> ==> std::map<...>
<pair> ==> std::pair<...>
etc.
Post Reply