I've been at a loss as how to convert the std::string to char (Line 40). I've tried c_str() and a few other things, but it's really confusing when the pointers are thrown in there. I know I'm kind of asking you guys to do it but I don't know what else to do :/.

#include <iostream>
#include <string>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <new>
#include <string.h>

using namespace std;

bool fileExists(const char *fileName)
    ifstream infile(fileName);
    return infile.good();

int main ()

    vector <string> GNames;
    vector <string> GAliases;

    if ( fileExists("GName.txt") == 0 || fileExists("GAlias.txt") == 0 )

        cout << "Title of 'Name' file should be: GName" << endl;
        cout << "Title of 'Alias' file should be: GAlias" << endl;

    } else {

        string fileline;
        ifstream tstream("GName.txt", ifstream::in);
        if (tstream.good())
            while (!tstream.eof())
                  getline(tstream, fileline);
                  char * str;
                  str = new char (fileline);
                  char * pch;
                  pch = strtok (str," ");
                  while (pch != NULL)
                    pch = strtok (NULL, " ");
        } else {
            cout << "ERROR 101: Can't open file" << endl;

        cout << "Game generation completed" << endl;


return 0;

Recommended Answers

All 2 Replies

Use the string::c_str() method to extract a const c-string. Also, line 39 should be this:

char * str = ::strdup(fileline.c_str());

and eliminate line 40...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.