473,698 Members | 2,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(tes tText);

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 1629
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.com wrote 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(tes tText);

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*******@roun dtripllc.comwro te in message
news:%2******** ********@TK2MSF TNGP05.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 PtrToStringChar s, Marshal::PtrToS tringAnsi,
Marshal::PtrToS tringUni, and friends.
>
"Lee J" <me@nowhere.com wrote 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::ifstrea m infile;
String^ testText;

openFileDialog 1->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(te stText);

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
3395
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, MathFuncPtr> predefinedFunctions; // lots of other stuff void makeDictionary(){ predefinedFunctions=&F::f_sin(); } };
12
1494
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 do I plan to help them fix such a buggy product. The IDE closes down unexpectedly: For no reason at all, the IDE aborts (shuts down); prompts for permission to send an error report to Microsoft. Debug windows: There are problems with variables...
3
1703
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
1530
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 after a failed build there are minor ones as well kind of, such as: - take 20 seconds to save a file. => which gives: before compiling spend 10 minutes saving files
1
1221
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 screwed up and can't compile C++ at all. why is that? various error such as can't find 'cl' etc... If you look in Tools=>Option=>Project and Solutions=>VC++ Directories I have, for exemple, only 2 directories in the executable directory list:
4
5057
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++ Toolkit 2003 from Microsoft website. It has command line compiler cl.exe, but it can not open Solution files. VS uses Devenv.exe and devenve.com to open Solutions, but they are not included in the free toolkit.
2
1052
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 displays the value Form1. The Name property is associated with code (and won't accept spaces anyway).
3
6436
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 get an error at the end of the SQL server install phase 'Invalid endpoint'. (Note SQL server express gets installed OK) If I run SQL server express SP2 setup directly it I don't get the error
7
2883
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 make a stand alone exe file in MS VC++ 2005 Express Edition? If you also have experience in Borland C++ Builder on the same question, I will also appreciate you for your reply. Thank you!
0
9156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4361
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2323
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.