Thread: Problems with int to char...

  1. #1
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002

    Angry Problems with int to char...

    I'm using the following code to use an int variable (hard coded here but normally cinned by a user) as the beginning of a filename, this code should work, but i think i may be messing up my steps, i get the error: 'can not turn char* to int' when i try to compile, here's the code...anyone know whats wrong??
    int studentID="04390"
    template <class T> std::string toString(const T& val) {
    	std::ostringstream strWriter;
    	strWriter << val;
    	return strWriter.str();
    int main() {
    	std::string filename=toString<int>(studentID) + ".xml";
    	std::ofstream file (filename.c_str());
    return 0;
    thanks for your help
    PHP and XML
    Let's talk about SAX

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    int studentID="04390"

    Simple. You are trying to set StudentID (an int) to the string "04390" (a char *).

    You may want to do this instead:

    int StudentID = 4390; //(notice, no preceding zero's are included)


    char* StudentID = "04390";

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  2. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  3. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  4. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM