DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Fri, 20 Jul 2007 16:19:40 -0700,    posted on: microsoft.public.dotnet.framework.clr        back       

Thread Index
  1    Allen Maki
          2    Göran Andersson
          3    Allen Maki


Read and write to Console or a file   
How come line 1 will output garbage to the screen, but line 2 will output a 
good number to a file?

How can I make line 1 out put a good number to the screen







String* dayStr = System::DateTime::Now.ToString("dd");

Int32 dayInt = System::Int32::Parse(dayStr);

Console::WriteLine("the day is {0}", __box(dayInt) );     // Line 1



                                      .

                                       .

                                       .





String* path = new String("_1D.txt");  // will read the time from a file

FileStream * fs = new FileStream(path, FileMode::Open);

BinaryReade* br = new BinaryReader(fs);

Int32 day    = br->ReadInt32();



fs = new FileStream(S"_1k.txt", FileMode::Create); //will write the time to 
another file

BinaryWriter* bw = new BinaryWriter(fs);

Br->Write( day); 
//Line  2
Date:Fri, 20 Jul 2007 16:19:40 -0700   Author:  

Re: Read and write to Console or a file   
Allen Maki wrote:

> How come line 1 will output garbage to the screen, but line 2 will output a 
> good number to a file?


What kind of "garbage"? The wrong number? Random characters? An exception?


> How can I make line 1 out put a good number to the screen
> 
> String* dayStr = System::DateTime::Now.ToString("dd");
> 
> Int32 dayInt = System::Int32::Parse(dayStr);


Why do you create a string and parse it? Why not simply:

Int32 dayInt = System::DateTime::Now::Day;


> Console::WriteLine("the day is {0}", __box(dayInt) );     // Line 1
> 
> 
> 
> String* path = new String("_1D.txt");  // will read the time from a file
> 
> FileStream * fs = new FileStream(path, FileMode::Open);
> 
> BinaryReade* br = new BinaryReader(fs);
> 
> Int32 day    = br->ReadInt32();


You forgot to close the stream here.


> fs = new FileStream(S"_1k.txt", FileMode::Create); //will write the time to 
> another file
> 
> BinaryWriter* bw = new BinaryWriter(fs);
> 
> Br->Write( day); 
> //Line  2
> 


-- 
Gran Andersson
_____
http://www.guffa.com
Date:Sat, 21 Jul 2007 19:25:56 +0200   Author:  

Re: Read and write to Console or a file   
Hi Gran,



I really appreciate your help.  I learn a new way to deal with DateTime 
which is (Int32 CurHour = System::DateTime::Now.Hour), but now I have a 
problem.



Format1(your format):  Int32 dayInt = System::DateTime::Now.Day;




Format 2 (The one I use before):  Int32 dayInt = System::Int32::Parse(dd);

                                                                        Int32 
CurHour = System::DateTime::Now.Hour;



Now, after I use format 2 instead of format 1, the things went to the 
opposite, which is I get garbage (random character) when I write to files 
and get good numbers when writing to the screen.



To answer your questions:



Why do you create a string and parse it?



The answer is, that was the only way for me to get good number into the 
file.



What kind of "garbage"? The wrong number? Random characters? An exception?



The answer is Before I was getting wrong numbers.






"Gran Andersson"  wrote in message 
news:eCDR2w7yHHA.1184@TK2MSFTNGP04.phx.gbl...

> Allen Maki wrote:
>> How come line 1 will output garbage to the screen, but line 2 will output 
>> a good number to a file?
>
> What kind of "garbage"? The wrong number? Random characters? An exception?
>
>> How can I make line 1 out put a good number to the screen
>>
>> String* dayStr = System::DateTime::Now.ToString("dd");
>>
>> Int32 dayInt = System::Int32::Parse(dayStr);
>
> Why do you create a string and parse it? Why not simply:
>
> Int32 dayInt = System::DateTime::Now::Day;
>
>> Console::WriteLine("the day is {0}", __box(dayInt) );     // Line 1
>>
>>
>>
>> String* path = new String("_1D.txt");  // will read the time from a file
>>
>> FileStream * fs = new FileStream(path, FileMode::Open);
>>
>> BinaryReade* br = new BinaryReader(fs);
>>
>> Int32 day    = br->ReadInt32();
>
> You forgot to close the stream here.
>
>> fs = new FileStream(S"_1k.txt", FileMode::Create); //will write the time 
>> to another file
>>
>> BinaryWriter* bw = new BinaryWriter(fs);
>>
>> Br->Write( day); //Line  2
>>
>
> -- 
> Gran Andersson
> _____
> http://www.guffa.com 
Date:Sat, 21 Jul 2007 22:23:44 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us