How to do basic file I/O in Visual C++ or in Visual C++ .NET

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2005
Posts: 15,397
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

How to do basic file I/O in Visual C++ or in Visual C++ .NET

 
0
  #1
Jul 7th, 2009
Has anyone tried to write this tutorial using VC++ 2008 Express? The article claims to be written with VC++ 2005. But I thought 2005 and 2008 used compatible versions of CLR language. I'm getting all kinds of compiler errors -- for example String* str; instead of using String^ str; and creating objects with new instead of gcnew. The last straw for me was while attempting to implement the section concerning FileInfo class. None of the FileInfo methods Microsoft has in that article work.
Last edited by Ancient Dragon; Jul 7th, 2009 at 3:12 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 681
Reputation: Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of 
Solved Threads: 132
Tom Gunn's Avatar
Tom Gunn Tom Gunn is offline Offline
Practically a Master Poster

Re: How to do basic file I/O in Visual C++ or in Visual C++ .NET

 
0
  #2
Jul 7th, 2009
The tutorial tells you what to do to compile as Managed C++ instead of C++/CLI:
Note In Visual C++ 2005, you must add the common language runtime support compiler option (/clr:oldSyntax) to successfully compile the previous code sample as Managed C++. To add the common language runtime support compiler option, follow these steps:
  1. Click Project, and then click ProjectName Properties.
    Note ProjectName is a placeholder for the name of the project.
  2. Expand Configuration Properties, and then click General.
  3. In the right pane, click to select Common Language Runtime Support, Old Syntax (/clr:oldSyntax) in the Common Language Runtime support project settings.
  4. Click Apply, and then click OK.

For more information about common language runtime support compiler options, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx (http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx)
-Tommy (For Great Justice!) Gunn
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,397
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to do basic file I/O in Visual C++ or in Visual C++ .NET

 
0
  #3
Jul 7th, 2009
When I change that I get this warning
1>cl : Command line warning D9035 : option 'clr:oldsyntax' has been deprecated and will be removed in a future release
Then get other errors, such as this one (line 19 in the code shown below).
Form1.h(22) : error C2059: syntax error : 'public'
  1. namespace test5 {
  2.  
  3. using namespace System;
  4. using namespace System::ComponentModel;
  5. using namespace System::Collections;
  6. using namespace System::Windows::Forms;
  7. using namespace System::Data;
  8. using namespace System::Drawing;
  9. using namespace System::IO;
  10. /// <summary>
  11. /// Summary for Form1
  12. ///
  13. /// WARNING: If you change the name of this class, you will need to change the
  14. /// 'Resource File Name' property for the managed resource compiler tool
  15. /// associated with all .resx files this class depends on. Otherwise,
  16. /// the designers will not be able to interact properly with localized
  17. /// resources associated with this form.
  18. /// </summary>
  19. public ref class Form1 : public System::Windows::Forms::Form
  20. {
  21. public:
  22. Form1(void)
  23. {
  24. InitializeComponent();
  25. <snip>
Last edited by Ancient Dragon; Jul 7th, 2009 at 3:48 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 681
Reputation: Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of 
Solved Threads: 132
Tom Gunn's Avatar
Tom Gunn Tom Gunn is offline Offline
Practically a Master Poster

Re: How to do basic file I/O in Visual C++ or in Visual C++ .NET

 
0
  #4
Jul 7th, 2009
That looks like generated C++/CLI code. None of that fancy stuff will work under the oldSyntax setting. You have to start with an empty project and build it manually, I think. Or find a tutorial that covers the new syntax. The MSDN library has example code in multiple langauges for all of the classes in System::IO and they are up to date for the framework version. C++/CLI is always included from what I've seen. For example.
Last edited by Tom Gunn; Jul 7th, 2009 at 4:00 pm.
-Tommy (For Great Justice!) Gunn
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,397
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to do basic file I/O in Visual C++ or in Visual C++ .NET

 
0
  #5
Jul 7th, 2009
I was finally able to get that FileInfo stuff figures out, not by MSCN or google but by IntellSense. So now I can continue on with that tutorial.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC