writting to a folder, and editing strings

This is a discussion on writting to a folder, and editing strings within the C++ Programming forums, part of the General Programming Boards category; alright, I have two problems, first of all I want to write to a folder, the folder is predetermined (not ...

  1. #1
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110

    writting to a folder, and editing strings

    alright, I have two problems, first of all I want to write to a folder, the folder is predetermined (not a variable), but the file name is a variable, but I want it to write to: saves\command.svg
    command is the character string (variable)

    I tried:
    strcpy(command,"saves\",command,".svg");

    edit> nm gotit, sorry, strcat fixed it

    edit2> it outputs a file testest, I set command to test and ran these before opening the file:
    [CODE] strcat("saves\\",command);
    strcat(command,".svg");[\CODE]

    I used:
    ofstream load(command);
    to open the file, but it didn't work
    Last edited by Dark Nemesis; 08-16-2003 at 11:15 PM.

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    You can only use strcat on non-constant strings. (String literals are constant, and they're anything like "this". )

  3. #3
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    this generates a file with no extention in the programs directory, not under saves
    Code:
    int loadchar(int charid, char command[8]) {
    	char file[20];
    
    	strcpy(file,"saves\\");
    	strcat(file,command);
    	strcat(file,".svg");
    
    	ofstream load(command);
    
    	load << "test";
    
    	load.close();
    	return 0;
    }
    any help?

  4. #4
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    You're supposed to use 'file' in the ofstream, not 'command'

  5. #5
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    I just noticed that, but thank-you, I feel really dumb now...
    here's a new question: deleting from strings, how is it done?

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Originally posted by Dark Nemesis
    here's a new question: deleting from strings, how is it done?
    Can you be a bit more specific ? Give an example or something.

  7. #7
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    sure, like if I wanted to delete the last few characters in a string if I know what the characters are, but no the lenght, what would I use? I though about a loop to check each individual character in the string, and then find where the null character is, then rewrite the string with the deletion, is there an easier way?

  8. #8
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Here you can find some methods for nul-terminated string.

    It's easier to use a string variable. Here you can find some usefull methods.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21