|
Dump the char* and use std::string instead:
#include "stdafx.h"
#include <tchar.h>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream ifs("C:\\In.txt");
string line;
while (getline(ifs, line))
{
cout << line << endl;
}
return 0;
}
Steve
|
|
|
|
|
Hi!
getline() expects only a char* not a std::string. IT shows error.
|
|
|
|
|
There's a getline[^] which accepts std::string s. Have you added #include <string> to the include files? If you haven't added using namespace std; somewhere in the scope remember you need to use a fully qualified name: std::string .
Steve
|
|
|
|
|
|
Hi all,
i have an static text control when i use to display some text in Static control,use SetWindowText
my text is "Test & Test Project" but its display like "Test _ Test Project" or "Test Test Project".
please tell me how can display the same text as it is whether it is contain 1 & or 2 &.
thank in advnace.
|
|
|
|
|
Use double ampersand - "Test && Test Project"
|
|
|
|
|
Try using two "&" characters: "Test && Test Project".
Steve
|
|
|
|
|
its a entry that is filled by user,how can i insist the user to enter && in place of &,
think if he did it but there no similarity again betwwn entered value and displayed value.
he enterd && but dispaly onle 1 &,
please tell me how can i handle it.
|
|
|
|
|
The cleanest approach would be to add the SS_NOPREFIX[^] style to the control.
Steve
|
|
|
|
|
Yes its done now thanks.
same problem with DrawText when i want to print this text.
please tell me how can i solve this.
|
|
|
|
|
If you look at the documentation for DrawText[^] you'll find this:
DT_NOPREFIX
Turns off processing of prefix characters. Normally, DrawText interprets the mnemonic-prefix character & as a directive to underscore the character that follows, and the mnemonic-prefix characters && as a directive to print a single &. By specifying DT_NOPREFIX, this processing is turned off. For example,
Example:
input string: "A&bc&&d"
normal: "Abc&d"
DT_NOPREFIX: "A&bc&&d"
Compare with DT_HIDEPREFIX and DT_PREFIXONLY.
Steve
|
|
|
|
|
|
You do not want the user to enter it that way.
Just replace & with && before calling SetWindowText .
You could use CString::Replace for this.
|
|
|
|
|
<br />
BOOL WINAPI MySetThreadContext(HANDLE hThread, CONST CONTEXT *lpContext)<br />
{<br />
CString s;<br />
BOOL nResult=CopySetThreadContext(hThread,lpContext);<br />
s.Format("%x",lpConText->Dr0);<br />
MessageBox(NULL,s,s,MB_OK);<br />
return nResult;<br />
}<br />
This's hook SetThreadContext.
This can be blocked to the address you set up Dr0 how that kind of block you want to change the address register value Dr0 it?
For example, Dr0 address change eip to 00123456 then how to get this 00123456 intercept?
|
|
|
|
|
Does anyone know of a way to prevent context switch in a block of code?
As far as I can tell (unless I am wrong) Critical Sections do not guarantee not to switch context, it simply means threads can't access a shared resource.
I am looking for some API that will guarantee an atomic execution of a block of code (if this API even exists)
Shay
|
|
|
|
|
As far as I know, this is something impossible on Windows. This is for security reasons: imagine you "lock" at the begining of your code but forget to "unlock". It would mean that your computer is completely frozen (only your app runs, but it can't get any input because they are not processed).
|
|
|
|
|
Yep, pretty much what I had in mind...
Thanks.
|
|
|
|
|
You can get close by temporarily elevate the thread priority to real time. But even then there's no guarantee.
|
|
|
|
|
That's what I ended up doing.
|
|
|
|
|
Read this somewhere that calling SetThreadPriority also resets the quantum of the thread.
So calling SetThreadPriority repeatedly can infact give exclusive control to the thread, at least in theory.
But I would never recommend elevating priority of a thread to real time.
Rather you should design your code in such a way that it handles re-entrancy.
|
|
|
|
|
That was interesting. I had a quick look around, but could only find information that this was a problem in Windows NT.
Regarding reentrant code, I don't think the OP's reason was thread safety. Just to prevent a task switch.
|
|
|
|
|
I suppose kernel code can. See, for instance [^].
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
nice but in kernel I prefer to use more orthodox stuff
My question was for something I am doing in user space.
|
|
|
|
|
Well, if it is tricky in kernel space...
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
can't be done in user mode, and that is how it has to be in order to protect one user/app from another user/app.
|
|
|
|