-
wchar_t file I/O [was: please review the code...]
please review my code
i want to get individual parameters and then write in the file "abc"
i am sending the three pointer to the function writelog
*starttime is pointing to start time it is of the form
12.10.23.100(hr.min.sec.milisec)
similarly endtime is pointing towards end time
and cmdname is pointing to the name.
function writelog(wchar_t* cmdname, wchar_t*starttime,wchar_t*endtime)
{
min = wstrtok(starttime + 1,L'.');
sec = wstrtok(null,L'.');
milisec = wstrtok(null,L'.');
logstream = Xnew ofstream("abc.log",log:append)
abc<<"min"<<min<<"sec"<<sec<<"milisec"<<milisec
abc<<"componenetname"<<"\t"<<cmdname<<endl;
abc<<"starttime"<<"\t"<<starttime<<endl;
abc<<"endtime"<<"\t"<<endtime<<endl;
}
this program is right syntactically as well as logically?
2>
int stratmin = _wtoi( const wchar_t min );
will thi statement convert wchar_t type min to int type min?
-
The code isn't correct because you have to use the wide file stream objects: wofstream, wifstrean etc, when you write wchar_t characters to them.
Danny Kalev
-
i have done few modification please check the syntax as well as logic ..will it work?
void writelog(wchar_t* cmdname, wchar_t*starttime,wchar_t*endtime)
{
wchar_t *min = wstrtok(starttime + 1,L'.');
wchar_t *sec = wstrtok(null,L'.');
wchar_t * milisec = wstrtok(null,L'.');
// will above statements separate out min , sec and milisec from the string?
here L specifier works with '.' .i have read that on one website.
well my wchar_t (string ) is like 11.12.23.100(hr.min.sec.milisec)
now strattime is pointing to this string
i want the pointer to each component viz min sec mili
so above i am using wstrtok.if nul doesnt work then what should i use to get the refrence?
wofstream a_file ( "test.txt", ios::app );
a_file<<"componenetname"<<"\t"<<cmdname<<endl;
a_file<<"starttime"<<"\t"<<starttime<<endl;
a_file<<"endtime"<<"\t"<<endtime<<endl;
}
will this work now?i want to write the wchar_t (string) to the file test.txt
-
You're almost there. However, the following statement and those that follow it are wrong:
Code:
a_file<<"componenetname"<<"\t"<<cmdname<<endl;
You're using a quoted char string instead of a wchar_t string:
a_file<< L"componenetname" << L"\t" <<cmdname<<endl;
I wouldn't use endl either, I think should work properply but you can use a more explicit delimter such as L'\n' or L','.
Of course, the easiest way to confirm that everything's working correctly is running the program and then testing the files (you want to write another routine that opens that file and reads the data therein, just to make sure that it contains the correct data).
Last edited by Danny; 07-06-2005 at 07:18 AM.
Danny Kalev
-
Thanx a lot .....
swapnil.
-
error while compiling
hi
when i started compiling the program
wofstream a_file ( "test.txt", ios::app );
a_file<< L"componenetname" << L"\t" <<cmdname<<L'\n' ;
a_file<<L"componenetname"<<L"\t"<<starttime<<L'\n' ;
a_file<<L"starttime"<<L"\t"<<endtime<<L'\n' ;
i got the error :a_file was not defined .
now how to construct the file and define it ....i guess error may be bcoz of i am not using constructor for wofstream and as well as for file......
but i donno how to do that.....
plezz help me by providing the syntax/code for the above error.
thanx.
swapnil.
-
i think this can be solution for my above problem plezzz check this
i want to write the data in file abc.txt
static wostream *logstream;
logstream = Xnew wofstream("abc.txt",ios::app);
logstream<< L"componenetname" << L"\t" <<cmdname<<L'\n' ;
logstream<<L"starttime"<<L"\t"<<starttime<<L'\n' ;
logstream<<L"endtime"<<L"\t"<<endtime<<L'\n' ;
here i am declaring logstream as pointer of type wostream
then using logstream i am trying to append the data at the end of the file.
the file abc.txt doesnt exist already ....willl wofstream constructor will create the file ?
else need i write the code to create the file for first time?
thank you?
-
Did you #include <stream> in the program? And did you use a using declaration such as
Code:
using std::wofstream;
?
Danny Kalev
-
no i didnt use that std::wofstream...
-
I meant <fstream>. You need to #include it and refer to std::wofstream to make this code compile.
Danny Kalev
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks