 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
keyz182
Joined: 23 May 2008 Posts: 2
|
Posted: Sat May 24, 2008 12:01 am Post subject: [Solved] String and Vector woes |
|
|
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: |
#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("Files", 0, 1, 1);
using namespace std;
vector<string> slist;
//#define printf pspDebugScreenPrintf
//There be dragons here:
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback,
NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread,
0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
void getList(char *path){
char newPath[80];
SceUID fd = sceIoDopen(path);
if (fd >= 0) {
char *curdir;
for (;;) {
struct SceIoDirent entry;
memset(&entry, 0, sizeof(struct SceIoDirent));
if (sceIoDread(fd, &entry) <= 0)
break;
if ((entry.d_stat.st_mode&FIO_S_IFDIR)==FIO_S_IFDIR) {
if(!strcmp(entry.d_name,".") || !strcmp(entry.d_name,"..")){
} else {
//printf("%s [DIR]\n", entry.d_name);
sprintf(newPath, "%s%s", path,entry.d_name);
//printf(" ==> %s\n",newPath);
getList(newPath);
sprintf(curdir,"%s",newPath);
}
} else {
string tmp(entry.d_name);
//sprintf(tmp,"%s", entry.d_name);
slist.push_back(tmp);
//printf("%s [FILE]\n", entry.d_name);
//a->insertBack(0,*entry.d_name);
}
}
}
sceIoDclose(fd);
}
int main () {
pspDebugScreenInit();
SetupCallbacks();
char file[40] = "ms0:/MUSIC/";
getList(file);
/*song tmp;
for(int i = 0; i < list.size(); i++){
tmp = list.at(i);
printf("%s\n",tmp.path);
}*/
sceKernelSleepThread();
return 0;
}
|
Log:
| Code: |
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: In function ‘void getList(char*)’:
main.cpp:81: error: variable ‘std::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: In destructor ‘std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]’:
mksfo 'File Manipulation' PARAM.SFO
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_vector.h:203: instantiated from ‘std::vector<_Tp, _Alloc>::vector(const _Alloc&) [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]’
main.cpp:22: instantiated from here
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_vector.h:119: error: invalid use of undefined type ‘struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stringfwd.h:56: error: declaration of ‘struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h: In function ‘void std::__destroy_aux(_ForwardIterator, _ForwardIterator, __false_type) [with _ForwardIterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >*]’:
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h:155: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >*]’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h:182: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>) [with _ForwardIterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_vector.h:272: instantiated from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]’
main.cpp:22: instantiated from here
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h:121: error: cannot increment a pointer to incomplete type ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h: In function ‘void std::_Destroy(_Tp*) [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’:
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h:122: instantiated from ‘void std::__destroy_aux(_ForwardIterator, _ForwardIterator, __false_type) [with _ForwardIterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >*]’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h:155: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >*]’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h:182: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>) [with _ForwardIterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_vector.h:272: instantiated from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]’
main.cpp:22: instantiated from here
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stl_construct.h:107: error: invalid use of undefined type ‘struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >’
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/bits/stringfwd.h:56: error: declaration of ‘struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >’
make: *** [main.o] Error 1
make: 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 |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Sat May 24, 2008 12:13 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
keyz182
Joined: 23 May 2008 Posts: 2
|
Posted: Sat May 24, 2008 12:18 am Post subject: |
|
|
| thanks, I was advised to change #include <string> to #include <string.h> seems changing it back did the trick |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Sat May 24, 2008 3:46 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|