|
std::transform will do the trick with the right functor. If you just want to randomly jumble the characters in the range std::random_shuffle will work as well.
Looking at your examples it looks like you only want to fiddle with the vowels so std::transform is the way to go.
Cheers,
Ash
|
|
|
|
|
Hi!
I've declared the string like this:
std::string test = "S R Tendulkar";
If I call, test.transform(); or test.random_shuffle(); , I got the following errors:
1>d:\test\main.cpp(53) : error C2039: 'transform' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1>d:\test\main.cpp(54) : error C2039: 'random_shuffle' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
How to call the functions?
|
|
|
|
|
They're not members of std::string - they're defined in <algorithm> .
std::transform takes a range over which you want to do something, a destination and what you want to do. So if you wanted to convert all vowels to the next in a sequence you could do something like:
std::pair<char, char> vowel_step =
{
std::pair<char, char> ( 'a', 'e' ),
std::pair<char, char> ( 'e', 'i' ),
std::pair<char, char> ( 'i', 'o' ),
std::pair<char, char> ( 'o', 'u' ),
std::pair<char, char> ( 'u', 'a' )
};
std::map<char, char> vowel_map( &vowel_step[ 0 ], &vowel_step[ 5 ] );
class vowel_transformer
{
public:
char operator()( char c )
{
std::map<char, char>::const_iterator iter( vowel_map.find( c ) );
if( iter != vowel_map.end() ) return iter->second;
return c;
}
};
std::string aesc( "aescleal" );
std::transform( aesc.begin(), aesc.end(), aesc.begin(), vowel_transformer() );
That should convert "aescleal" into "eiscliel". To get the effect you want define a class to do the tranformation on a per-character basis and work out the range you want to operate on.
Cheers,
Ash
PS: If you're using C++0x you can simplify a lot of the boiler plate.
Edited as I'm a crap proof reader
|
|
|
|
|
Hi Ash,
I found your post very intresting and published at my website http://www.visualcpp.org/?p=368[^]. please check if you ok with it otherwise i can remove it, if you don't like it
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Any messages I post here are fair game for reuse/reposting - if I didn't want other people to use what I wrote I wouldn't post it here!
Glad you found it interesting as well.
Cheers,
Ash
|
|
|
|
|
Hi all,
what is the max rows and max column size of the CListControl?
|
|
|
|
|
Since the documentation doesn't say anything about the maximum limits, I guess it would either depend on the available process memory or the maximum value an int can hold since the index is specified using an int variable.
|
|
|
|
|
When an app crashed, VC displayed a message:
The instruction at "0x00123456" referenced memory "0x00654321" could not be read.
If the error caused by a pointer, I guess, the second value "0x00654321" is the pointer value (such as CWnd*pc; value is (int)pc ), and first value "0x00123456" is memory address where the pointer resides.
Is it correct?
|
|
|
|
|
includeh10 wrote: Is it correct?
Almost. The second number is the address referenced, which bears a relation to the pointer, but is not necessarily exactly the same. For example, a->b uses a pointer of value a , but the actual location referenced is offsetof(the_struct, b) higher. The first number is the address of the failing instruction, which is almost certainly NOT where the pointer lives. The preceding instruction(s) probably fetch or calculate the pointer value to use.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
The error message means exactly what it says - whatever instruction the processor was executing when the instruction pointer hit 0x00123456 caused the problem. The problem was that it tried reading something at an address of 0x00654321 which wasn't a lump of memory it could read.
So it could be loads of things:
- you tried casting something you shouldn't to a pointer and the variable you cast had a value of 0x00654321
- a pointer contained a value of 0x00654321 and you tried dereferencing it
- you scribbled all over memory using memset and managled a pointer
- you scribbled all over memory and managed to corrupt a thread's stack
- you're trying to use memory that you've freed
- you're accessing a local variable after it's gone out of scope
Whatever it is it's pretty insanitary and might have the unfortunate effect of moving around in memory when you're trying to find it. You might even think you've fixed it when all you've done is move it so that when a customer or professor runs it they find it
To stop this sort of thing happening:
- don't manually manage memory
- don't manually manipulate memory (memset, memcpy, that sort of thing)
- don't use pointers
Cheers,
Ash
|
|
|
|
|
Hi,
CDC* pDc = GetDC();
CSize cSize = pDc->GetTextExtent( "1", 1 );
CRect cRect ( 0, iPadding, cSize.cx, cSize.cy );
pDc->DrawText( "1", 1, &cRect , DT_CENTER|DT_VCENTER|DT_NOCLIP );
The above code displays the text "1" horizontally in cRect .
To display the text vertically, i did as follows:
CFont newFont;
newFont.CreateFont(24, 0, 900, 900, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");
CFont* pFont = pDC->SelectObject(&newFont);
pDC->DrawText("1", 1, &cRect, DT_CENTER|DT_VCENTER|DT_NOCLIP);
pDC->SelectObject(pFont);
newFont.DeleteObject();
But in this case, I couldnt get any text displayed.
Please can someone help me to get the text displayed vertically. How should cRect be manipulated to draw the text vertically?
Mary
|
|
|
|
|
Did you see here or here?
Have you tried playing with different CRect values? You've probably just made the drawing area too restrictive.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
hey guys i am taking some parameters from an initialvalues.ini file and write the new values in it too for the upcoming times. I have learned read/write the .ini files in vc++ and my program works fine with these codes:
[code]
GetPrivateProfileString(_T("Settings"), _T("File_List"), _T("") ,lastsession, 255,
_T("C:\\Documents and Settings\\stajyervestek1\\Desktop\\Copy of Dilara\\Dilara\\initial_paths.ini"));
.
.
.
WritePrivateProfileString(_T("Settings"), _T("File_List"), m_list,
_T("C:\\Documents and Settings\\stajyervestek1\\Desktop\\Copy of Dilara\\Dilara\\initial_paths.ini"));
[/code]
However, i want this program to work in other circumstances, too. mainly, i want this "C:\\Documents and Settings\\stajyervestek1\\Desktop\\Copy of Dilara\\Dilara" part to be the home directory of the user. I tried to write .\\ instead but the program crashed when i tried to use "writeprivateprofilestring". Can you give me any advice to achieve my goal?
thanks in advance
|
|
|
|
|
dilara semerci wrote: However, i want this program to work in other circumstances, too. mainly, i want this "C:\\Documents and Settings\\stajyervestek1\\Desktop\\Copy of Dilara\\Dilara" part to be the home directory of the user.
Sounds like you need SHGetFolderPath() .
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
there are tons of examples about this SHGetFolderPath() i tried to read them all but would you mind give me the idea to use it? Thanks in advance
|
|
|
|
|
dilara semerci wrote: ...would you mind give me the idea to use it? Thanks in advance
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
In my program, i want to parse the complete URL string into tokens of hostname, port, file, querystring parameters?.
Is there any generic recommended way of doing it , or any libraries available?
modified on Monday, August 9, 2010 10:16 AM
|
|
|
|
|
|
Have you tried UrlGetPart() ?
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
|
I've written a stub dll that I would like to use for testing purposes. I would like to replace the full-feature dll with the stub and be able to run the program without re-compiling.
I have written the stub dll and a little driver program that builds against the full-feature lib but when it runs, it loads the stub dll. Unfortunately that does not work, as it complains it can't find the entry point for the functions.
I ran depends on the driver and I can see that its loading the stub dll as expected, but the calls do not resolve. The calls are listed as "unbound" entry point, but the functions from the dll are being exported.
When I compare the full-feature dll and the stub dll in depends I can see that the entry points for the functions are not the same.
Any ideas what I need to do to make it work?
Thanks.
modified on Monday, August 9, 2010 10:49 AM
|
|
|
|
|
VentsyV wrote: When I compare the full-feature dll and the stub dll in depends I can see that the entry points for the functions are not the same.
Any ideas what I need to do to make it work?
I would have though that is fairly obvious. If you wish your application to run via a stub dll then the stub must contain all the functions that the application tries to link to. How else can the calls be resolved?
It's time for a new signature.
|
|
|
|
|
A MDIParent Wnd has many MDIchild Wnds, and also few child dialogs.
Dialogs are created this way --- CAutoDlg *pDlg = new CAutoDlg; pDlg->Create(IDD_AUTOCARD,this);
I want to cascade only a specific type of dialogs, say dialogs of CAutoDlg type only.
If i give MDICascade() it cascades all the child windows and dialogs under the MDIFrame. Is there any other un-conventional way other than calling SetWindowPos for each dialog, based on the position of the previous dialog?
|
|
|
|
|
Elsie wrote: Is there any other un-conventional way other than calling SetWindowPos for each dialog
Not that I know of, but it should be fairly simple to write your own cascading. Write a function that takes the type of window as parameter (typically CAutoDlg) and iterate over all your child frames/dialogs and position the ones inheriting from the supplied base type using IsKindOf().
|
|
|
|
|
I have developed a project in mfc dialog based vc++, i have put a combobox and added an integer typed variable m_number. I want to use this number in the other methods of the dialog but when i write m_number it takes -1, how can i assign the values in the combobox to that variable so that i can use it?
|
|
|
|
|