For those new to message boards please try to follow a few simple rules when posting your question.
Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
Keep the subject line brief, but descriptive. eg "File Serialization problem"
Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
No advertising or soliciting.
We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
I am new to C++17, and am trying to figure out how to use string_view. I have three functions that parse a string of comma separated values:
beforecomma reports the string before the first comma,
aftercomma reports the string after the first comma,
slicecomma returns the string before the first comma and updates the original string to that part after the first comma.
These functions all work properly in their current forms using just string. Now, I am trying to update them as beforecomma2, aftercomma2, and slicecomma2, to take advantage of string_view. However, I am getting some unexpected results. I am hoping someone out there can tell me why this is happening and what I am doing wrong.
First, the functions:
std::string_view beforecomma2 (std::string_view line)
auto found = line.find(',');
string_view aftercomma2 (string_view line)
auto found = line.find(',');
if ((found==std::string::npos) || (found==line.size()-1)) return"";
while ((out==' ') && (out.size()>0)) out=out.substr(1,out.size());
string_view slicecomma2 (string& line)
I run these functions with the following main, that just calls the functions beforecomma2 and aftercomma2.
Now I get the output of:
01234, 5678, 90, 78902, 999999, 333333
A few things wrong here.
First, the first item 01234 is skipped.
Second, a comma appears with the second and third printed items, when it should not.
Third, the fourth and fifth items are truncated to 78 when it should be 78902 and 99999 when it should be 999999
Fourth the last item, 333333, should not be repeated and should not appear truncated with a leading space.
So, it is not working as I expected it to work.
I would say that there is something here that I do not understand about string_view, but since I do not understand it I do not know what that is. Can anyone enlighten me?
I need you to tell me everything you wish you had access to/known/ been encouraged to explore with programming at a young age.
My son has been interested in coding since he was 4. My dad and him began to learn it together for fun, but he has long passed my dad's abilities at age 10. He can write many languages from memory and often hand-writes pages of coding in his notebooks while at school. Sometimes I think he dreams in code. He also really loves math and chemistry.
I do not know how to help him. There are no resources available for his age group in our area- it is all geared towards high school students, with a high focus on cyber security (which is awesome, just not alot of choices). He is bored with CodeAcademy. I don't really even understand a lot of what he is saying...
Is there an online program for kids, or a well-monitored program with all ages, that he can share his ideas, learn from others, be helped towards the direction he is interested in going? Like, an extracurricular of sorts, but for programmer kids!?
Sorry for the long post... any and all advice is welcomed.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
There's no mechanism within C++ to do that. In fact, modern run time systems are designed so that program data spaces are different for each program invocation. For example:
$ cat example.c
printf("&n = %p\n" , &n);
$ for ((i=0;i<4;++i)); do ./example; done
&n = 0x7fff2ddda67c
&n = 0x7ffdece1243c
&n = 0x7ffe42e7d2bc
&n = 0x7fffd2e78b2c
Note that even this simple program gives different addresses for the address of int n on successive runs. This is to make it difficult for any malicious program to interfere with and modify a running program, or to predict where a program will place data.
Also note that in any modern OS (outside of some embeded applications), you are dealing with virtual addresses anyway, so where your process thinks an object is and where the object actually is in physical memory are completely different, so you need to know things like the value page frames and things to work out a physical address of an object in memory.
Outside of some sort of educational value, I can't see any up side to always getting the same address when calling new, so maybe you might want to think about why you want this behavior and come up with a new plan.
The question is stupid, there is no way a dynamic heap manager can guarantee it wont give the memory space away to some other call for memory allocation. To do what you asked it would have to keep the memory "available" anyhow, so for the love of all things coding just declare the thing static in that case (unless you actually want a global).
My C++ is rusty with string objects but it should be something like
static char* str = char;
In C it is simpler
static char str;
Problem solved it now has the same address everytime locally, and effectively does the same thing that any crazy heap manager doing what you asked would have to do.
I am assuming you are going to change the string at times, so you want a variable not a constant.
Main Question: Is it possible to set a tree item image (CTreeCtrl::SetItemImage) without having to build a CImageList ?
I have to build different images corresponding to the items state and I would like to be able to create the image dynamically (lot of TransparentBlt) instead of having to list and build all the images and add them statically to the image list.
i have a default item image and I TransparentBlt state images on it
for example, an item can have the state1 enabled, and will display the appropriate image representing state1.
an another item can have state1 and state4 and will display an image with the state1 and state4
Now, I have to create the imagelist for all combinations of states at compile time and call the SetItemImage with the image list index.
I'd like to be able to simply call something like:
myTree.SetItemImage( hItem, BuildMyItemImage(hItem ) ); // and that would dynamically build an image depending on the states and just use it.
I was wondering if it is possible to connect to an FTPS server using CInternetSession/CFtpConnection and if so how. Or will I need to use a library to achieve this. I've searched around on the internet but can't find a definitive answer.
I can access the server using FileZilla with no problems. I know very little about FTP/FTPS but my guess is that CInternetSession/CFTPConnection do not support SSL(TSL); I've been doing quite a lot of reading but haven't found anything to confirm this however. I think my next step is to try out curl.
I hadn't seen that particular post, but I've seen most of the links listed there. I did try adding ftps:// to the server name, as suggested in that link, but that returns and invalid url error. I was hoping for a simple solution but it looks to be more complicated than I hoped.
Thanks for the help!
Last Visit: 17-Nov-19 4:32 Last Update: 17-Nov-19 4:32