Jump to content
  • Advertisement
Sign in to follow this  

stupid chars

This topic is 5089 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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";

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

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,



Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites
ok im having a little trouble here shouldnt this work?


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 =

make.exe: *** [Main.o] Error 1
Execution terminated

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!