"fstream" Help!

Hello everyone. Just having a little bit of an issue. I'm using Visual Studio 2010 and this won't compile correctly. It compiled just fine when I used Visual Studio 6.0.

Error Message:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1
1>Build started 12/21/2011 9:21:23 AM.
1>InitializeBuildStatus:
1>  Creating "Debug\Text Based RPG.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1>  All outputs are up-to-date.
1>  Text Based RPG.cpp
1>c:\users\kathy\desktop\nathaniel\text based rpg\text based rpg\text based rpg.cpp(18): error C2661: 'std::basic_ofstream<_Elem,_Traits>::open' : no overloaded function takes 0 arguments
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.56
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Source Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int input_int;
string input_string, name;

int char_create()
{
	cout << "Hello! What's your name?" << endl;
	cout << ">";
	getline(cin, name);
	cout << "Hello " << name << endl;
	ofstream character_data(name + ".txt.");
	character_data.open();
	character_data << name << endl;
	character_data.close();
	return 0;
}

int main()
{
	char_create();
	cout << "Character successfully created!" << endl;
	
	cin.ignore();
	return 0;
}


My expected output would be:
Hello! What is your name?
>Nathaniel Sheller
Hello Nathaniel Sheller
Character successfully created!
Try:
 
ofstream character_data((name + ".txt").c_str());

Thank you.
The compiler is correct, character_data.open(); in line 18 is invalid C++. Just remove that line.

Also, your file name is going to end with ".txt.", I think you meant ".txt"
It now works. Thank you.
Topic archived. No new replies allowed.