|
I am new to the field of VC++....can anyone please tell me as how to create a program that reads a text file, line by line....and if possible how to read each line starting from a particular character to a specified number(of characters)
|
|
|
|
|
one place to start would be to look at msdn.microsoft.com for iostream and fstream.
*.*
cin >> knowledge;
|
|
|
|
|
Hi! Keegan
I realy don't understand what you wanted to say...was just going through what you told me , but to no avail.....
|
|
|
|
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/html/_iostream_fstream.3a3a.fstream.asp
thats an insane description of fstream. I'll show you an example of one way to write to files here:
string filename = "data.txt";
ifstream inFile(filename.c_str());
ofstream Out;
string word;
inFIle >> word;
Out << word;
ifstream and ofstream are more or less identical in terms of use to cin and cout. Once you define the input and output streams, they work the exact same way (more or less). If you have any more questions, feel free to email me.
*.*
cin >> knowledge;
|
|
|
|
|
Consider using a CStdioFile for reading your file. Construct an instance of the class for the file you want to read from. You can call the ReadString method on it to get a line of text from your file into a CString. Then you can make use of all the methods of CString to get to only the part of the line in the string you are interested in. Technically you are reading the whole line. You then parse the string for what you need.
Lorenz Prem
Microsoft Corporation
|
|
|
|
|
Hello again,
I have a document-view app that uses a standard windows timer to display some animation on the view. The problem is, when I set the timer period to less than 200 msec (say 100 msec) some (or
all, I'm not sure) modal dialogs do not come to the foreground
and I have to press the "Alt" key to make them visible.
They all have the "Foreground" attribute set in the resource editor.
I read an article somewhere else in codeproject about attaching the main window thread to the dialog, but I don't get it.
When should I do this? Before I call DoModal() in my view, in the dialog's OnInitDialog() or what?
Thanks in advance.
|
|
|
|
|
You could try creating the dialog with WS_TOPMOST in the style parameter
|
|
|
|
|
Hi guys
How can I add code to the Standard Save on a menu of a SDI app?
Best Regards
Dr.Pi
|
|
|
|
|
|
If your using MFC override the Serialize() function in your derived class, call the base class function first and then add your code. I'm assuming you've set up the message map stuff for the standard save menu button correctly. If your using win32, then it depends...we need more info
|
|
|
|
|
Just noted JWood's response, if you want to do something extra before or after a save (pop a dialog box etc. then override OnSaveDocument(), but if you want to save extra stuff or mess with the io methods you'll need to override Serialize(). Hope this helps you. Check either of these methods out in MSDN for a deeper explanation. .
|
|
|
|
|
Thanks to everybody, I'll take a look on Serialize.
I had to save thinks like bool,float,arrays etc.. is then Serialize the place to do it? And then, later when I wanted to read it, is in Serialize too?
Best Regards
Dr. Pi
|
|
|
|
|
Replying to myself and waiting your answer.
I had to override serialize in each class where I have data to save, and then automatically when I call Save, all this data will be saved, and when I call Open, all this data will be retrieved (obviously if I implement correctly the serialize).
Is something like this?
if (ar.IsStoring())
{ // storing code
ar<<m_ncode
="" }
="" else
="" {="" loading="" code
="" ar="">>m_nCode
}
It doesnt' matter what m_nCode is?
Bast Regards
Dr.Pi
|
|
|
|
|
I know how to do this through explorer and how to 'open' and 'close' IO to the serial ports but I actually want to disable them.
How would I do this progmatically??
|
|
|
|
|
One solution is to disable the COM port. Check out this reference at MSDN.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/device_management_functions.asp
I am not familiar with serial ports, but try openning a connection and keep it alive at all time. That may block any I/O.
Kuphryn
|
|
|
|
|
dear all,
the following lines of code gives wrong value on windows 2000, but on every other operating systems it works fine
<br />
if (sDir.CompareNoCase("M") != 0)<br />
{<br />
.....<br />
}<br />
but if i use a variable with value "M"...it works fine.......
any guesses why
Regards
rIsHaBh
|
|
|
|
|
rishabhs wrote:
if (sDir.CompareNoCase("M") != 0)
use this instead..
if(!sDir.CompareNoCase("M"))
{
}
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
rishabhs wrote:
...the following lines of code gives wrong value...
Which means what? What does CompareNoCase() return in this case? What are you expecting it to return?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I assume sDir is a CString, you're not compiling for Unicode, and you're trying to test for sDir NOT being M (i.e. the if block should be executed if sDir is not M).
I can't see why this would fail on Windows 2000. CompareNoCase uses _tcsicmp , which translates to _stricmp for a non-MBCS, non-Unicode build. For an MBCS build, it translates to _mbsicmp . Check which of MBCS and/or UNICODE you're defining.
Apparently these functions are affected by the LC_CTYPE but not the LC_COLLATE locale parameter. I believe that the locale defaults to the C locale - see the documentation for setlocale .
See also the CodeProject BugList article[^].
|
|
|
|
|
This is probably a UNICODE vs. ANSI (MBCS) issue. If you change your code like this:
#include "tchar.h"
if (sDir.CompareNoCase(_T("M")) != 0)
{
}
that may help.
Software Zen: delete this;
|
|
|
|
|
when i tried to add function for user to edit data, the CString all work correctly but the float numbers become distorted after user edit the fields.
void CEtchDlg::OnEdit()
{
CString a,b,c,d,e,f;
float h,j,k,l;
GetDlgItemText(IDC_EID,a);
GetDlgItemText(IDC_TARGET1,b);
GetDlgItemText(IDC_PROCESS1,c);
GetDlgItemText(IDC_ETCHANT1,d);
GetDlgItemText(IDC_CONCENTRATE,e);
GetDlgItemText(IDC_REMARKS,f);
recordset->Edit();
recordset->SetFieldValue("a",(LPCSTR)a);
recordset->SetFieldValue("b",(LPCSTR)b);
recordset->SetFieldValue("c",(LPCSTR)c);
recordset->SetFieldValue("d",(LPCSTR)d);
recordset->SetFieldValue("e",(LPCSTR)e);
recordset->SetFieldValue("f",(LPCSTR)f);
recordset->SetFieldValue("h",(float)h);
recordset->SetFieldValue("j",(float)j);
recordset->SetFieldValue("k",(float)k);
recordset->SetFieldValue("l",(float)l);
recordset->Update();
}
|
|
|
|
|
When you need a char* , as in SetFieldValue, you need to access it via GetBuffer(0) and ReleaseBuffer(). Casting it your way (LPCSTR) is a bad practise.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Nah I disagree completely, using LPCSTR returns a constant pointer to a string, which is good if you're only going to read from it and NEVER alter it. GetBuffer(0) returns a MODIFIABLE char* which should be treated with care because you can munch memory and cause the app to crash. Its always good practice to use constants where you can, it offers a little protecting from making silly mistakes.
Alan.
|
|
|
|
|
Whoops, of course you are right. I mixed up LPCSTR and LPSTR :/
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Easy enough to do , all this LPCSTR, LPCTSTR, LPSTR stuff etc... its just asking for it really. I can see why LPSTR would be bad practice mind since the CString buffer isn't protected, as in GetBuffer(0) (which requires you to ReleaseBuffer before the changes are implemented), so cheers for pointing that out. I always use GetBuffer(0) but this discussion has just highlighted that it is the better coding practice of the two, which is nice to know .
|
|
|
|