Thread: question about using a string as a file location

  1. #1
    Registered User
    Join Date
    Feb 2006

    question about using a string as a file location

    hi i've never posted here before but ive got a problem and none of my friends could help me figure it out. basically i have a variable called fileloc, its a string entered by the user. my problem is how to i make this string the location where the file is written to. here is the part of my code in question
    #include <iostream>
    #include "Rectangle.h"
    #include <string>
    #include <fstream>
    using namespace std;
    #include <iomanip> // given to me by the tutor in room 320
    int main()
    	Rectangle r;
    	float l;
    	float w;
    	char answer;
    	string fileloc;
    	ofstream output;
    	//program info
    	cout<<"This is the rectangle program designed to find the perimeter and area of "<<endl
    		<<"rectangles of custom length and width which is input by the user and"<<endl
    		<<"finally print the output to a user selected file"<<endl<<endl;
    	// ask the user where to save it
    	cout<<"Where would you like to save the output file"<<endl;
    	//open the file, ios::out);
    and this is the error i get:

    ..\..\program 2\program 2\project 2.cpp(39) : error C2664: 'void std::basic_ofstream<_Elem,_Traits>:pen(const wchar_t *,std::ios_base:penmode,int)' : cannot convert parameter 1 from 'std::string' to 'const wchar_t *'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

    im not very good at c++ (still learning) so maybe i have made a stupid mistake but any help would be awesome thanks in advance

  2. #2
    Unregistered User
    Join Date
    Sep 2005

    Code:, ios::out);
    -- Rocky
    -- DreamSys Software (
    -- Free Tiff 2 PDF Library (

  3. #3
    Registered User
    Join Date
    Feb 2006
    thank you that worked great i really aprciate it

  4. #4
    pwns nooblars
    Join Date
    Oct 2005
    Portland, Or
    The problem is iostream expects a constant char array.

    explains the usage of c_str().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM