-2

i am new to programming, and i was making a program in which i made the user enter the name of file and then i want to move the file (into a folder known as item) . how should i do this ? i have tried to use the rename function but i am unable to do it.

    string name;
int passcode;
int accnumber;

clrscr ();

system("title Stock Management Program (Creating an account) ");

cout << "Enter Name:" ; // getting basic info
cin >> name;
cout << endl;

cout <<"Enter Account Number:";
cin >> accnumber;
cout << endl;

cout << "Enter your passcode (only numbers):";
cin >> passcode;

ifstream errcheck;
errcheck.open(name);

if (errcheck.fail())
{
    ofstream createacc; // creating account using fstream
    createacc.open (name);
    createacc << accnumber << endl;
    createacc << passcode << endl;
    createacc.close (); 

    string newname = "item\" + name; //problem
    int rename ( const char * name, const char * newname ); // PROBLEM
}
{
    cout << "Sorry account already exists! ";
    pause ();
}
  • i am unable to create a string containing "item\" –  Sep 23 '15 at 11:01
  • This really should be closed - it's been abandoned in horribly mixed up form for the better part of a year, and reflects a complete lack of understanding of programming - we have an attempt to use a function prototype as an invocation, a complete misunderstanding of what system() does, etc - the poster has either learned in the meantime, or lost interest, so the question is of no use now. – Chris Stratton May 27 '16 at 21:12

1 Answers1

1

Here you have a problem because backslash is an escape symbol (it will treat next symbols as text), use \\ it will be treated as single backslash.

string newname = "item\" + name; //problem

string newname2 = "item\\" + name; //ok

For you perpose it's better to use a file system lib, for example boost filesystem

Teivaz
  • 5,462
  • 4
  • 37
  • 75