Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2007

Tip: Looking for answers? Try searching our database.

VC++ Express, Strings and files - CONFUSED

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lee J - 20 Nov 2007 17:26 GMT
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
Peter Anthony - 20 Nov 2007 19:15 GMT
You might want to consider these classes instead for file manipulation:

StreamWriter class
http://msdn2.microsoft.com/en-us/library/system.io.streamwriter.aspx
StreamReader class
http://msdn2.microsoft.com/en-us/library/system.io.streamreader.aspx

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

> Gang,
> I am self taught in C and fairly proficient for last 20 years.  Don't
[quoted text clipped - 37 lines]
>
> Lee
Ben Voigt [C++ MVP] - 23 Nov 2007 16:03 GMT
> You might want to consider these classes instead for file manipulation:
>
[quoted text clipped - 4 lines]
>
> 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.

>> Gang,
>> I am self taught in C and fairly proficient for last 20 years.  Don't
[quoted text clipped - 38 lines]
>>
>> Lee

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.