Help

This is a discussion on Help within the C++ Programming forums, part of the General Programming Boards category; Hi everybody. How can I put a variable in this example Code: remove("C:\example\filename"); where filename is a variable. bye...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Location
    ALBANIA
    Posts
    6

    Help

    Hi everybody.
    How can I put a variable in this example

    Code:
    remove("C:\\example\\filename");
    where filename is a variable.

    bye
    Last edited by pitkini; 06-26-2005 at 04:21 AM.

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    
    int main()
    {
    
    string path;
    
    cout << "enter the desired path: ";
    cin >> path;
    
    remove(path.c_str());
    
    return 0;
    
    }
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main() 
    {
    	string myDirectory = "C:\\example\\";
    	string filename = "input.txt";
    
    	string myPath = myDirectory + filename;
    	remove(myPath.c_str());
    	
    	return 0;
    }

  4. #4
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main() 
    {
    	string myDirectory = "C:\\example\\";
    	string filename;
            cout << "File Name: ";
           getline(cin, filename, '\n');
    
    	string myPath = myDirectory + filename;
    	remove(myPath.c_str());
    	
    	return 0;
    }

  5. #5
    Registered User
    Join Date
    Jun 2005
    Location
    ALBANIA
    Posts
    6

    thanks

    Thanks everybody

  6. #6
    Registered User
    Join Date
    Jun 2005
    Location
    ALBANIA
    Posts
    6
    nothing of these worked. Was an error on:
    Code:
    remove(myPath.c_str());

  7. #7
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    
    int main()
    {
    
    char path[81];
    
    cout << "Enter the desired path:";
    cin >> path;
    
    //remove(path.c_str());
    remove(path);
    return 0;
    
    }
    maybe i'm not sure what's wrong the other samples worked fine.

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