stupid chars

Started by
13 comments, last by technomancer 19 years, 5 months ago
ok i have something like this char* Master_Enemy_Files[] = {"Enemy_One.txt"}; but i want that whole thing to be one element i could do a multidemntional array but thats a PAIN im using c++ and i just want a way to make a const char* {"blabla"}; to be one SINGE entity is there any way to do this
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
You mean like this?
std::string Master_Enemy_Files[10];Master_Enemy_Files[0] = "Enemy_One.txt";Master_Enemy_Files[1] = "Enemy_Two.txt";Master_Enemy_Files[2] = "Enemy_Three.txt";...
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
yes thats exactly what i mean but unless you have a really good way to transfer those strings to chars i cant use em
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Quote:
yes thats exactly what i mean but unless you have a really good way to transfer those strings to chars i cant use em


just use the c_str() method in the string class to convert to chars.

- Mike
[smack self on head] doa! i knew there was some easy funcion out there i should use thanks alot![grin]

oh BTW what library is c_str in??
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Why don't people like using the string class?
Rob Loach [Website] [Projects] [Contact]
its not that i dont like it in fact i love it but when inputting file names the function takes only chars
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Hi,

I think it's because people usually get taught char arrays first, so they stick with what they've originally learned. Some people feel more comfortable using already defined data-types instead of user-defined classes.

I have seen some people post threads around the internet talking about how inefficient the string class is because it wastes memory (like when you concatenate). But when you look at the big picture the difference is negligible. It would obviously depend on it's application though.

Just my 2 cents,

Later,

GCS584
what files must i include in order to use the c_str method because as of right now it says it dont exist here are the files i have so far

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <vector>
#include <stdlib.h> // Include this to use system()
#include <iostream> // Include our standard header
#include <string> // Include this to use strings
#include <fstream>
#include <libiberty.h>
#include "Ship.h"
#include "Enemy.h"
#include "Level.h"
#include "SDL.h"
#include "Input.h"
using namespace std;

or is this a member function like str1.c_str(char1)?

never mind figured it out its the later
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
ok im having a little trouble here shouldnt this work?

Enemy_List[One->Enemy_Vector->ID].c_str(Enemy_List_C);

string Enemy_List[]= "Enemy_1.bmp";
char* Enemy_List_C= "";

i get this error

Main.cpp:251: error: no matching function for call to `std::basic_string<char,
std::char_traits<char>, std::allocator<char> >::c_str(char*&)'
C:/MinGW/include/c++/3.3.1/bits/basic_string.h:717: error: candidates are:
const _CharT* std::basic_string<_CharT, _Traits, _Alloc>::c_str() const
[with _CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>]

make.exe: *** [Main.o] Error 1
Execution terminated
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie

This topic is closed to new replies.

Advertisement