|
Dear friends,
I have a CString object, say str ,and i want to know how to extract a specific set of characters from this str and store it in another CString object. Does there exist any function/ class for that?
Malini
|
|
|
|
|
Maybe CString::FindOneOf will be of some help. See MSDN for related documentation.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi All,
I do a project by using ADO+ACCESS+VC,
1. Reterive data from DB
2. Analyzing the data and calculate the new result, and the results are not the recordset.
3. Display the result on the UI.
while now I meet some difficulties.Requirement like the following:
1. Dynamic identity the total row and col num;
2. The grid should have Expand and Collapse function which can hide or show data in the same type.
3. Because the data is newly generated while not only reterived from db, so i have to write them down to the grid one by one.
Anyone can help me out??
Thanks in advance.
|
|
|
|
|
I am writing a backup program -- and would like to be able to backup large files. I don't want to run into any sort of sharing violations...
Is it possible for me to watch the file system, in order to monitor what files are being open in the system?
I'd like to abort the operation if someone wants access to the current file.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc.</A>
|
|
|
|
|
Hi,
I'm a student and newcommer in MFC. I have problem when I'm runing my program. An assertion failed window appear when I'm working on it. When I pressed retry button, debug stop in line 884 in file wincore.cpp.
=================================================
line 884 ASSERT((CWnd*)p == this); //must be us
=================================================
Is there any one that can help me? I don't know the problem that makes debug assertion failed. And what should I do to fix it?
thx b4
= amelia =
|
|
|
|
|
What happens if you trace through the code ? Did you read this comment in the code ? Does it apply to you ?
// Note: if either of the above asserts fire and you are
// writing a multithreaded application, it is likely that
// you have passed a C++ object from one thread to another
// and have used that object in a way that was not intended.
// (only simple inline wrapper functions should be used)
//
// In general, CWnd objects should be passed by HWND from
// one thread to another. The receiving thread can wrap
// the HWND with a CWnd object by using CWnd::FromHandle.
//
// It is dangerous to pass C++ objects from one thread to
// another, unless the objects are designed to be used in
// such a manner.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
That's the other problem, I do not understand the comment. i'm very new on MVC++ especially MFC. I read many articles and book and try some. I do not used to with the technical term. I do use thread. here is the code
==========================================================================
void CConversionDlg::OnAnyMove()
{
m_ListCC.SetCurSel(nCurrentCC);
m_ListCC.GetText(nCurrentCC, ccode);
// do something
::AfxBeginThread(ThreadCCList, this); //=> i'm imitate it from other project code
}
UINT ThreadCCList(LPVOID pDlg)
{
CConversionDlg* dlg = (CConversionDlg*) pDlg;
nCurrentNC++;
Sleep(1000);
dlg->CallAnyMove();
return 0;
}
===========================================================================
Can you explain more about my mistake?
thx
== amelia ==
|
|
|
|
|
It looks like you're doing exactly what the comment says not to - passing a CWnd object to
another thread.
While this isn't impossible to do, you must be calling a CWnd/CDialog method somewhere in your
second thread that can only be called on the thread the object was created on.
You may want to rethink your design a bit since using MFC CWnd objects simultaneously on multiple
threads is going to be problamatic at best. I can't provide any details since I have no idea
what you need to do in the dlg->CallAnyMove() call.
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Thanks for the answer Mark,
I'm using the thread simply to Recall void CConversionDlg::OnAnyMove until the end of data in the listbox.
So, my first call to void CConversionDlg::OnAnyMove will parsing data from first index in listbox then do some move. After it stop moving, the thread is called to renew listbox index(nCurrentNC) with the next index and recall the void CConversionDlg::OnAnyMove through the dlg->CallAnyMove(); . These will continue until the last index.
This is my code on CallAnyMove:
void CConversionDlg::CallAnyMove()<br />
{<br />
OnAnyMove();<br />
}<br />
Do you have any suggestion on redesigning my code without using thread? because I don't know any other way, yet.
Thx b4,
amelia
|
|
|
|
|
I don't think you need separate threads for this. Unless it's a lengthy operation that can run
in the background AND that requires so much time that the UI suffers then there's no need for it.
Even if you did need the extra thread, there's certainly no need to spawn a new thread every time
in OnAnyMove! Plus you haven't provided any synchronization method to prevent threads from
accessing objects simultaneously. That's why a firm understanding of what's going on is vital.
You should be able to do what you're doing by just calling the method(s) without separate threads.
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Writing multithreaded programs is hard and there are many surprising issues that pop up which simply don't exist in a single threaded program. I suggest that you think twice before using threads until you're more experienced with single threaded programming and have researched thread specific programming issues such a synchronisation, dead locks, thread affinity, race conditions, etc....
Steve
|
|
|
|
|
crieagu wrote: i'm very new on MVC++ especially MFC.
Then why in the world would you be bothering with threads? It's certainly not something a beginner should be attempting. Stick with the basics until you have a firm grasp on those, and then move on to something a bit more difficult.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thx for the question,
When I was looking around in help index(msdn)to find way to impliment my pseudocode(to recall OnAnyMove), I found threads. So, I read it and tried to use it.
It's running as what I wanted although Assertion windows appeared every time void CConversion::OnAnyMove is called. Then I'm looking for help to correct it, googling , read the articles about threads. And I just found that Thread is very difficult.
But, I'm still looking around to find a way to correct it. So, that I have something new to store in my brain
|
|
|
|
|
What exactly is it that you are trying to do?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I'm tring to find any suggestion to correct my program code so that I can fix and use it.
If I cannot use thread to my limitation knowledge, can any one tell me what other method that I can use to recall void CConversion::OnAnyMove
If that bother you or others, I'm really sorry.
|
|
|
|
|
crieagu wrote: If I cannot use thread to my limitation knowledge, can any one tell me what other method that I can use to recall void CConversion::OnAnyMove
Using a secondary thread to call a function/method is obviously inefficient. Just call the said function/method and be done with it. If you are trying to do something else, please elaborate.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi all
The below code is reading string and then tokenizin it and reading all the info. But i want to call a csv file and it should then read a string from dt file. So what midification should i do in the below code. Its main code, all the functions are defined well. So just wanna know how to include some extra code to open the file and read each line.
Thanks a lot
typedef struct
{
string firstName;
string surname;
unsigned int HouseNumber;
string StreetName;
string Town;
unsigned int PostCode;
string email;
unsigned int Phone;
}Person;
int main(int argc, char* argv[])
{
string data = "James,Bond,33,AlberStreet,Manchester,HG231,abc@yahoo.com,2552423";
string delimiter = ",";
StringTokenizer strtok(data,delimiter);
StringTokenizer strtok(data,delimiter);
if(strtok.countTokens() != 8)
{
cout << "!-Error-! Not enough tokens!" << std::endl;
}
else
{
Person person;
person.firstName = strtok.nextToken();
person.surname = strtok.nextToken();
person.HouseNumber = strtok.nextIntToken();
person.StreetName = strtok.nextToken();
person.Town = strtok.nextToken();
person.PostCode = strtok.nextIntToken();
person.email = strtok.nextToken();
person.Phone = strtok.nextIntToken();
}
}
|
|
|
|
|
Any help would be greatly appreciated.
I am stucked cos of this and cant move on with the rest of the coding till i solve this....
Thanks
|
|
|
|
|
For a software specialist you sure have a lot to learn
There are many ways to read a line of text from a file. I find the easiest way is to use CStdioFile::ReadString . If you do not or can not use MFC then you could use ifstream::getline although the shortfall of getline is that it requires a preallocated buffer. ifstream::operator >>(std::string &) also can be used but it breaks at any and all whitespaces.
If I am stuck using STL streams I use my own overloaded operator >>() :
std::tifstream& operator >>(std::tifstream &stream, std::tstring &string)
{
string.clear();
TCHAR ch = 0;
while (!stream.eof() && !stream.fail() && ch != _T('\n'))
{
if (0 != ch) string += ch;
stream._Read_s(&ch, 1, 1);
}
return stream;
} It might not be the most efficient, but it works as a standard C++ stream extractor and it extracts the entire string, from the start right up to the newline character.
Example usage - dumps a text file to the console output:
int _tmain(int argc, _TCHAR* argv[])
{
std::tifstream f(argv[1]);
std::tstring s;
while (!f.fail() && !f.eof())
{
f >> s;
std::tcout << s << std::endl;
}
return 0;
}
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
PJ Arends wrote: you could use ifstream::getline although the shortfall of getline is that it requires a preallocated buffer.
This isn't the case as I underdstand it. For example, consider the following code:
#include "StdAfx.h"
#include <iostream>
#include <string>
int main()
{
using namespace std;
string line;
if (getline(cin, line))
{
cout << "Line read was \"" << line << "\"" << endl;
}
return 0;
}
This code works (even on MSVC6!) but there is no preallocated buffer. Granted I'm not calling ifstream::getline but that's not where the method we need lives!
Steve
|
|
|
|
|
Learn something new every day, thanks!
All that being said, I still prefer MFC over fstreams for file handling.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
#include "StdAfx.h"
#include <iostream>
#include <string>
int main()
{
using namespace std;
string line;
if (getline(cin, line))
{
cout << "Line read was \"" << line << "\"" << endl;
}
return 0;
}
Steve
|
|
|
|
|
Hi thanks for the reply
Well in the code you mentioned you never opened any file.So what line is it reading.
Or here you hv just nt included dt as you giving example .
Well actually problem is that i have tried so many programs by now...but none of them are opening the file. I dont know where am i going wrong....just now i tested 3-4 different programs but same it doesnt open the file...I am real stucked here..i ll try with your code by adding
std::ifstream InFile( "data.txt" );...dont knw if it gonna work or not...
Thanks
|
|
|
|
|
The sample I gave reads from the standard input stream; the file used is the console or a file if input redirection is used. To use a file specific file use code like this:
#include "StdAfx.h"
#include <iostream>
#include <fstream>
#include <string>
int main()
{
using namespace std;
ifstream file("C:\\File.txt");
if (!file)
{
cerr << "Failed to open input file!" << endl;
return 1;
}
unsigned int count = 0;
string line;
while (getline(file, line))
{
cout << "Line " << ++count << ": " << line << endl;
}
return 0;
}
Steve
|
|
|
|
|
this is really strange...even this is not opening file.
I created file named File.txt under C folder as you mentioned the path.
and with data as
abc,def,ghi
jkl,mno
pqr
stu,vw,xyz
But its not even opening the file. Reading the file is the next step. It should first open the file atleast....
Oh its giving me a heading now.
Thanks for your reply
|
|
|
|