|
I cannot check the return value of FindFirstFile because if I set a breakpoint, I get the error that the code is unavalable for the current position at the line of the FindFirstFile function.
|
|
|
|
|
Megidolaon wrote: I cannot check the return value of FindFirstFile...
What's keeping you from doing this:
vector<string> files;
WIN32_FIND_DATA findData;
BOOL bFound = TRUE;
HANDLE handle = FindFirstFile(L"C:\\Dokumente und Einstellungen\\Student\\Eigene Dateien\\*.*", &findData);
if (handle != INVALID_HANDLE_VALUE)
{
while (bFound)
{
files.push_back(findData.cFileName);
bFound = FindNextFile(handle, &findData);
}
for (int k = 0; k < files.size(); k++)
cout << "Reading File:" << files[k].c_str() << endl;
}
else
cout << GetLastError() << endl;;
getchar();
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I use this, but I get this error when trying to read the names from the vector.
error C2664: 'void std::basic_ofstream<_Elem,_Traits>::open(const wchar_t *,std::ios_base::openmode,int)': Covertion of Parameter 1 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'const wchar_t *' not possible
I use wofstream to open the files, but I get that error when trying to read the names from the vector, yet I don't get an error when using a const filename (a random string literal).
Also I get this error multiple times from getline():
error C2784: "std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)": template-Argument for "std::basic_istream<_Elem,_Traits> &" could not be deducted from "std::wofstream"
It's the same error regardless if line is a string or a wstring .
|
|
|
|
|
This is a different problem altogether. What does your code to open and read from a file look like?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
This is my code:
vector<wstring> files;
WIN32_FIND_DATA findData;
BOOL bFound = TRUE;
HANDLE handle;
string name ="";
wofstream myfile;
wstring line;
handle = FindFirstFile(L"C:\\Dokumente und Einstellungen\\Student\\Eigene Dateien\\*.mp", &findData);
if (handle != INVALID_HANDLE_VALUE)
{
while (bFound)
{
files.push_back(findData.cFileName);
bFound = FindNextFile(handle, &findData);
}
}
else
{
cout << GetLastError() << endl;
}
for (int k = 0; k < files.size(); k++)
{
myfile.open(files.at(k));
while (myfile.eof() == false)
{
getline(myfile, line);
wcout << line << endl;
}
myfile.close();
}</wstring> It's pretty much the same as you posted, except that I use wofstream instead of ofstream and wsring for line instead of string.
And I use wcout instead of cout .
.mp files are just txt files with a different extension.
|
|
|
|
|
Megidolaon wrote: wofstream myfile;
This should be an "input" file since you are reading from it.
Megidolaon wrote: myfile.open(files.at(k));
at() returns a string , not a const char * . Hint: use the c_str() method.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thanks, now I don't get an error anymore.
However, it still doesn't work properly.
The program does nothing.
myfile.eof == false () never is wrong, apparently the file end is never reached.
I set a breakpoint and files contains 3 strings at runtime (this is correct).
Each of the files has 43 lines for a total of 129 lines;
I use
counter++;
cout << counter << ": "; Where counter is an int , starting a 0, to output the line numbers.
It passes 129 almost instantly and the while loop is infinte and line always is "" .
How come?
Why doesn't open () actually open the files or at least gives me some kind of error, why it won't work?
And more importantly, how does it work?
Thanks.
|
|
|
|
|
Have you tried something like:
while (myfile.good())
{
myfile.getline(line, sizeof(line));
wcout << line << endl;
}
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I just tries it changing line 's tpye to
WCHAR* line;
But now the pogram does nothing.
It doesn't even show the line numbers anymore.
I used breakpoints and looks like myfile.good () always returns false .
|
|
|
|
|
Megidolaon wrote: WCHAR* line;
Are you allocating memory for line ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I just changed it to
WCHAR line[2000]; then to
WCHAR* line = new WCHAR; and finally to
WCHAR* line = new WCHAR[]; The program still does nothing in all cases.
|
|
|
|
|
Why not just leave it as:
wstring line; That way you don't have to be concerned with allocating too little or too much memory.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I had that first, but then the string remains empty and never gets filled.
No matter how I do it, the program doesn't ouput the content of the files.
|
|
|
|
|
Hello,
I have a CStatic on CMDIChildWnd but I am not able to change its background color.
I have tried using CWnd functions
CStatic* Static = new CStatic;
CDC* pDC = Static->GetDC();
pDC->SetBkMode(OPAQUE);
pDC->SetBkColor(RGB(150,150,255));
Pritha
|
|
|
|
|
Handle the WM_CTLCOLORSTATIC notification and return the brush to be used to paint the control.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
First of all, in your piece of code you have instantiated a CStatic object but have not created a static control (see CStatic::Create).
And BTW: where/why do you want to put a static control in the MDI child frame window?
Ovidiu Cucu
Microsoft MVP - Visual C++
Cofounder CODEXPERT.RO
|
|
|
|
|
thanks
Yes I do have the Create function.
How do I use WM_CTLCOLORSTATIC ?
Should I call the OnCtlColor() ?
Thanks
Pritha
|
|
|
|
|
No.
It will be called by the system while initializing the controls.
You simply have to return the appropriate brush from the message handler.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
You need to declare this event.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Thank you
It helped me a lot.
|
|
|
|
|
Hello,
There was a query on the same lines.I am many a times confused which are the fucntions that are called by the system automatically which are not.
Now in this case why the creation of CStatic calls OnCtlColor().
Thanks,
Pritha
|
|
|
|
|
Again you dont need to call OnCtlColor.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hello,
I wanted to understand the functions that are directly called by the system and the reason behind it.
Prithaa
|
|
|
|
|
We suppose you made a program Windows send messges to your program if you need to these messages you can declare events for them like WM_MOUSE* or WM_PAINT and etc.You dont need to call windows events because windows sends them to your program for exmaple you need to change color of a static control so you tell to Windows that I need to this event with declare this event.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hello,
Thanks for the reply.
but how do I know exactly which functions are called by the system an which ones I am suppose to call. is there any article which makes this clear.
Prithaa
|
|
|
|