Visual C++ 2010 Express Text file help

Hello, I am currently trying to create a simple form which allows the user to choose the file name and file content; but with it's location pre-defined.
However, my main problem is that I want to set the location and file-name as a single thing, as you'll see in my code. However I keep getting the same error messages :

1
2
3
4
5
6
7
8
1
1>  Write to text file.cpp
1>c:\users\luke\documents\visual studio 2010\projects\write to text file\write to text file\Form1.h(182): error C2664: 'System::IO::StreamWriter::StreamWriter(System::IO::Stream ^,System::Text::Encoding ^)' : cannot convert parameter 1 from 'System::String ^' to 'System::IO::Stream ^'
1>          No user-defined-conversion operator available, or
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\luke\documents\visual studio 2010\projects\write to text file\write to text file\Form1.h(189): error C2664: 'System::IO::StreamWriter::StreamWriter(System::IO::Stream ^,System::Text::Encoding ^)' : cannot convert parameter 1 from 'System::String ^' to 'System::IO::Stream ^'
1>          No user-defined-conversion operator available, or
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Here is my full 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

#pragma once

namespace Writetotextfile {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	
	using namespace System::Diagnostics;
	using namespace System::IO;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Label^  txtNameTag;
	protected: 
	private: System::Windows::Forms::TextBox^  textFileName;

	private: System::Windows::Forms::Label^  txtBodyTag;
	private: System::Windows::Forms::TextBox^  textFileBody;


	private: System::Windows::Forms::Button^  AcceptButton;
	private: System::Windows::Forms::Button^  CancelButton;
	private: System::Windows::Forms::TextBox^  textFileLocation;
	private: System::Windows::Forms::Label^  addExtensionHint;


	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->txtNameTag = (gcnew System::Windows::Forms::Label());
			this->textFileName = (gcnew System::Windows::Forms::TextBox());
			this->txtBodyTag = (gcnew System::Windows::Forms::Label());
			this->textFileBody = (gcnew System::Windows::Forms::TextBox());
			this->AcceptButton = (gcnew System::Windows::Forms::Button());
			this->CancelButton = (gcnew System::Windows::Forms::Button());
			this->textFileLocation = (gcnew System::Windows::Forms::TextBox());
			this->addExtensionHint = (gcnew System::Windows::Forms::Label());
			this->SuspendLayout();
			// 
			// txtNameTag
			// 
			this->txtNameTag->AutoSize = true;
			this->txtNameTag->Location = System::Drawing::Point(12, 9);
			this->txtNameTag->Name = L"txtNameTag";
			this->txtNameTag->Size = System::Drawing::Size(86, 13);
			this->txtNameTag->TabIndex = 0;
			this->txtNameTag->Text = L"Name of text file:";
			// 
			// textFileName
			// 
			this->textFileName->Location = System::Drawing::Point(117, 6);
			this->textFileName->Name = L"textFileName";
			this->textFileName->RightToLeft = System::Windows::Forms::RightToLeft::Yes;
			this->textFileName->Size = System::Drawing::Size(208, 20);
			this->textFileName->TabIndex = 1;
			this->textFileName->Text = L"example.txt";
			// 
			// txtBodyTag
			// 
			this->txtBodyTag->AutoSize = true;
			this->txtBodyTag->Location = System::Drawing::Point(12, 47);
			this->txtBodyTag->Name = L"txtBodyTag";
			this->txtBodyTag->Size = System::Drawing::Size(82, 13);
			this->txtBodyTag->TabIndex = 3;
			this->txtBodyTag->Text = L"Body of text file:";
			// 
			// textFileBody
			// 
			this->textFileBody->Location = System::Drawing::Point(117, 44);
			this->textFileBody->Multiline = true;
			this->textFileBody->Name = L"textFileBody";
			this->textFileBody->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
			this->textFileBody->Size = System::Drawing::Size(322, 112);
			this->textFileBody->TabIndex = 4;
			// 
			// AcceptButton
			// 
			this->AcceptButton->Location = System::Drawing::Point(270, 162);
			this->AcceptButton->Name = L"AcceptButton";
			this->AcceptButton->Size = System::Drawing::Size(108, 23);
			this->AcceptButton->TabIndex = 9;
			this->AcceptButton->Text = L"Accept and Create";
			this->AcceptButton->UseVisualStyleBackColor = true;
			this->AcceptButton->Click += gcnew System::EventHandler(this, &Form1::AcceptButton_Click);
			// 
			// CancelButton
			// 
			this->CancelButton->Location = System::Drawing::Point(384, 162);
			this->CancelButton->Name = L"CancelButton";
			this->CancelButton->Size = System::Drawing::Size(55, 23);
			this->CancelButton->TabIndex = 10;
			this->CancelButton->Text = L"Cancel";
			this->CancelButton->UseVisualStyleBackColor = true;
			this->CancelButton->Click += gcnew System::EventHandler(this, &Form1::CancelButton_Click);
			// 
			// textFileLocation
			// 
			this->textFileLocation->Location = System::Drawing::Point(12, 164);
			this->textFileLocation->Name = L"textFileLocation";
			this->textFileLocation->Size = System::Drawing::Size(252, 20);
			this->textFileLocation->TabIndex = 11;
			this->textFileLocation->Text = L"C:/Users/Luke/Documents/Text Files";
			// 
			// addExtensionHint
			// 
			this->addExtensionHint->AutoSize = true;
			this->addExtensionHint->Location = System::Drawing::Point(331, 9);
			this->addExtensionHint->Name = L"addExtensionHint";
			this->addExtensionHint->Size = System::Drawing::Size(132, 13);
			this->addExtensionHint->TabIndex = 12;
			this->addExtensionHint->Text = L"(Don\'t forget file extension)";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(475, 190);
			this->ControlBox = false;
			this->Controls->Add(this->addExtensionHint);
			this->Controls->Add(this->textFileLocation);
			this->Controls->Add(this->CancelButton);
			this->Controls->Add(this->AcceptButton);
			this->Controls->Add(this->textFileBody);
			this->Controls->Add(this->txtBodyTag);
			this->Controls->Add(this->textFileName);
			this->Controls->Add(this->txtNameTag);
			this->Name = L"Form1";
			this->Text = L"Write to text file";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
private: System::Void browseButton_Click(System::Object^  sender, System::EventArgs^  e) {
			Process::Start("explorer.exe");
			}
private: System::Void CancelButton_Click(System::Object^  sender, System::EventArgs^  e) {
//			this->Hide();
			Application::Exit();
			}
private: System::Void AcceptButton_Click(System::Object^  sender, System::EventArgs^  e) {

if (textFileBody->Text == "")
{
StreamWriter ^outFile= gcnew StreamWriter(textFileLocation->Text, textFileName->Text);
outFile->Write("FILE EMPTY");
outFile->Write(DateTime::Now);
outFile->Close();
}
else
{
StreamWriter ^outFile= gcnew StreamWriter(textFileLocation->Text, textFileName->Text);
outFile->Write(textFileBody->Text);
outFile->Write(DateTime::Now);
outFile->Close();
}
}
};
}


Any help would be greatly appreciated.

Thanks,
Dowzer. ☮
Im new to this and i might not be right but when you see error like this :
cannot convert parameter 1 from 'System::String ^' to 'System::IO::Stream ^

this means that you are trying to convert from System::String ^' to 'System::IO::Stream ^ SO go to google and search for " how to convert System::String ^' to 'System::IO::Stream ^ "

Also you might try something like this:

StreamWriter ^outFile= gcnew StreamWriter(System::IO::Stream(textFileLocation->Text) , textFileName->Text);
Topic archived. No new replies allowed.