473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VC++ Express, Strings and files - CONFUSED

Gang,
I am self taught in C and fairly proficient for last 20 years. Don't
program much, just little utilities for work. Been wanting to create
windows forms and found MS VC++ Express. Installed it, bought book, etc.

Book doesn't cover files. From other sources I have the following:

#pragma once
#include <string>
#include <fstream>

//in a buttonclick function

std::ifstream infile;
String^ testText;

openFileDialog1->ShowDialog(); //Search for file and put name in
textBox1->Text = openFileDialog1->FileName; // a textbox on the form and in
testText = textBox1->Text; // a text variable.

I then want to open the file listed in textBox1 and testText.

infile.open(testText);

That doesn't work. I get an error, C2664

I am totally confused by different strings, different ways of opening files,
managed, unmanaged .....

I created the project as just a CLR Windows Forms Application in VC++
Express. All I need to do is get a filename from openFileDialog into a
textbox for reading and another for writing from another textbox, read the
lines from one file, manipulate the string a bit and write it out to the
other.

Any help appreciated.

Lee
Nov 20 '07 #1
2 1614
You might want to consider these classes instead for file manipulation:

StreamWriter class
http://msdn2.microsoft.com/en-us/lib...eamwriter.aspx
StreamReader class
http://msdn2.microsoft.com/en-us/lib...eamreader.aspx

They are much easier to use than the old fstream approach.

"Lee J" <me@nowhere.comwrote in message
news:Xn********************@69.28.186.120...
Gang,
I am self taught in C and fairly proficient for last 20 years. Don't
program much, just little utilities for work. Been wanting to create
windows forms and found MS VC++ Express. Installed it, bought book, etc.

Book doesn't cover files. From other sources I have the following:

#pragma once
#include <string>
#include <fstream>

//in a buttonclick function

std::ifstream infile;
String^ testText;

openFileDialog1->ShowDialog(); //Search for file and put name
in
textBox1->Text = openFileDialog1->FileName; // a textbox on the form and
in
testText = textBox1->Text; // a text variable.

I then want to open the file listed in textBox1 and testText.

infile.open(testText);

That doesn't work. I get an error, C2664

I am totally confused by different strings, different ways of opening
files,
managed, unmanaged .....

I created the project as just a CLR Windows Forms Application in VC++
Express. All I need to do is get a filename from openFileDialog into a
textbox for reading and another for writing from another textbox, read the
lines from one file, manipulate the string a bit and write it out to the
other.

Any help appreciated.

Lee

Nov 20 '07 #2

"Peter Anthony" <po*******@roundtripllc.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
You might want to consider these classes instead for file manipulation:

StreamWriter class
http://msdn2.microsoft.com/en-us/lib...eamwriter.aspx
StreamReader class
http://msdn2.microsoft.com/en-us/lib...eamreader.aspx

They are much easier to use than the old fstream approach.
C++ iostreams are much easier for pure I/O, the difficulty is, as the OP
noted, mixing the different types of strings.

The System::IO::* classes mentioned will accept the .NET gotten from a .NET
textbox.

At some point though, you'll need to use native routines. The functions for
converting strings are PtrToStringChars, Marshal::PtrToStringAnsi,
Marshal::PtrToStringUni, and friends.
>
"Lee J" <me@nowhere.comwrote in message
news:Xn********************@69.28.186.120...
>Gang,
I am self taught in C and fairly proficient for last 20 years. Don't
program much, just little utilities for work. Been wanting to create
windows forms and found MS VC++ Express. Installed it, bought book, etc.

Book doesn't cover files. From other sources I have the following:

#pragma once
#include <string>
#include <fstream>

//in a buttonclick function

std::ifstream infile;
String^ testText;

openFileDialog1->ShowDialog(); //Search for file and put name
in
textBox1->Text = openFileDialog1->FileName; // a textbox on the form and
in
testText = textBox1->Text; // a text variable.

I then want to open the file listed in textBox1 and testText.

infile.open(testText);

That doesn't work. I get an error, C2664

I am totally confused by different strings, different ways of opening
files,
managed, unmanaged .....

I created the project as just a CLR Windows Forms Application in VC++
Express. All I need to do is get a filename from openFileDialog into a
textbox for reading and another for writing from another textbox, read
the
lines from one file, manipulate the string a bit and write it out to the
other.

Any help appreciated.

Lee

Nov 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Serengeti | last post by:
Hello, in my class I have a map that translates strings to pointers to some member functions. The code goes like this: class F { typedef void (Function::*MathFuncPtr)(); std::map<std::string,...
12
by: John Gabriel | last post by:
lThe compiler output report is seldom correct: Problems here involve not being able to generate an accurate compile report. There are so many problems and I am not on Microsoft's payroll. Neither...
3
by: RYoung | last post by:
Hi all, Using VC Express Beta 2, Just a simple class so far cause I can't get past this error: error C3861: 'CoInitialize': identifier not found public ref class Class1 {
14
by: Lloyd Dupont | last post by:
it's only 2 hours I'm using it and I'm already mad from it's unproductivity feature. - my most hated feature being: you can't save your file (because it's used by VC# express). Very typicall...
1
by: Lloyd Dupont | last post by:
I have VS.NET 2005 standart edition. Before installing it I had installed VC++ express. I did modify some directory variable in VC++ express to have some project working. Now VS.NET is all...
4
by: youpak2000 | last post by:
Hi, I'm working on a VC++ project developed using Visual Studio 2003 and 2005. I want to compile the solutions from command like without installing VS IDE. I downloaded a free Visual C++...
2
by: Petded | last post by:
Hi, i found this extract regarding vc++.net express edition from MS. Quote: Make certain that you edit the Text property and not the (Name) property beneath the Design category, which also...
3
by: Steve | last post by:
Hi All I downloaded Sql server 2005 express SP2 and attempted to modify the Bootstrapper package files as I did with SP1 When i try to install SQL server as part of my VS 2005 deployment app I...
7
by: driplet | last post by:
I am using MS VC++ 2005 Express Edition to make some windows application programs. I found that the exe files I built on one computer cannot be run on the other. Could any body please tell me how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.