Ofstream Problem

This is a discussion on Ofstream Problem within the C++ Programming forums, part of the General Programming Boards category; my code is. Code: #include <iostream> #include <string> #include <fstream> using namespace std; int main(){ string text; string name; ofstream ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    151

    Ofstream Problem

    my code is.
    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    
    using namespace std;
    
    int main(){
    	string text;
    	string name;
    	ofstream test;
    
    	cout<<"Enter some text\n";
    	getline(cin, text);
    
    	cout<<"enter the file name with the extension and path(ex. c:/users/jon/filename.txt)\n";
    	getline(cin, name);
    	test.open(text);
    	test<<text;
    	test.close();
    	system("pause");
    }
    and the error I got was |17|error: no matching function for call to`std::basic_ofstream<char, std::char_traits<char> >:: open(std::string&)'|

  2. #2
    Registered User
    Join Date
    Jan 2010
    Posts
    3
    What IDE and compiler are you using? This code seems fine and works fine.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Code::Blocks, and I know it worked fine when i used visual c++.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,826
    This:
    Code:
    test.open(text);
    should be:
    Code:
    test.open(text.c_str());
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  2. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  3. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM

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