|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
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.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
I am trying to get comfortable using "vector".
I have a function "returning" hardware parameters I need to process further "upstream" -
including "main".
I can pass a vector <string> by reference or have been told to define "local vector" and "return" if from the function.
I am not sure how "return vector" really works and have not tried it yet.
The function returning "vector <string> " syntax is scary...
Could I return pointer to locally defined vector ?
( Or is is even feasible ?)
Is there a specific resource I could read ?
Something similar to this example , but with "return * vector - string "?
<pre>
#include<bits/stdc++.h>
using namespace std;
void func(vector<int> &vect)
{
vect.push_back(30);
}
int main()
{
vector<int> vect;
vect.push_back(10);
vect.push_back(20);
func(vect);
for (int i=0; i<vect.size(); i++)
cout << vect[i] << " ";
return 0;
}
|
|
|
|
|
Your code looks good to me.
If you want func to return a vector, it should allocate it on the heap, and returning it in a unique_ptr would be better than just returning a raw pointer. But it looks like you want to update a vector that might already have entries, so passing it by reference makes sense.
EDIT: func isn't a function template; it simply takes a vector argument. The term function template refers to a function defined by template <typename T> func ...
modified 4hrs 5mins ago.
|
|
|
|
|
Hi Guys,
I have an app which does not use latest common control library. This app have Combo box which is in old style (like 3d style) but now we need to modernize the combo control like Flat (new window 10 style) without using latest common control library.
Can anybody help?
|
|
|
|
|
That is a contradiction in terms. You cannot have the modern style and still use the old library. However, it may be possible if you implement the OwnerDraw property.
|
|
|
|
|
There are many examples of CMFCRibbonComboBox that display simple text. I am actually looking for a CMFCRibbonComboBox example that display image or something like graphic, or say is ownerdraw.
Unless I mistake, I think CMFCRibbonComboBox class and inherited classes have ownerdraw capabilities since in afxribboncombobox.cpp there is a Draw and OnDrawLabelAndImage and others functions with CDC arguments.
Unfortunately, without step by step example, it is very difficult to implement such a class.
Any links or suggestions are welcomed
Pierre
|
|
|
|
|
There are plenty of examples of using OwnerDraw on controls. Adding it to this class will be no different.
|
|
|
|
|
|
|
These are derived from CComboBox, not from CMFCRibbonComboBox.
We are in a C++ MFC thread
|
|
|
|
|
Sorry for the cryptic nature of this question just trying to condense as much as I can.
I am trying to write a program in "C" which has a twist on the normal echo command in XPSP3
XP echo does not allow you to remove EOL characters when you redirect into text file with the >
I think they call it CRLF. However in my wanderings I have come across some "C" code that I think could compile a useful program. Here is some background info to illustrate:
The program that I hope to use would be called ECO.COM would be commandline for usage in CMD
ECO would be furnished with a flag (-X) that would give the user the choice to include the CRLF removal or would just be used just like echo command in XP without the -X flag. The ECO.COM file would be restricted to one line (80 Chars) long so the following could take place. The user could type for example
ECO.COM -X SET VARIABLE= (the ECO.COM would have with the -X flag to strip out the end CRLF so once the
SET VARIABLE= line was ridected to text file could easily be appended (>>) with a second ECO command or text file all on the same line. The resultant Text file could then be renamed to a .CMD file & called from another batch file thus setting the given %Variable%
I think they call it backticks or command substitution or some call it back quotes anyway here is the code which I have sought & tried to compile to create ECO.COM/EXE but it is not working can someone assist to make it work Please I think it would be very useful alternative to SET/P option in XPCMD?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* setting flag to remove crlf */
int main()
{
for (i = 1; i < argc; i++) {
/* Check for a switch (leading "-"). */
if (argv[i][0] == '-') {
/* Use the next character to decide what to do. */
switch (argv[i][1]) {
case 'x':
printf("flag a was called\n");
break;
}
}
}
/* part of script that echos 80 chars on one line */
int echo()
{
char input[80];
while(fgets(input, 80, STDIN)){ //read from STDIN (aka command-line)
printf("%s\n", input); //print out what user typed in
memset(input, 0, strlen(input)); //reset string to all 0's
return 1;
}
/* go to exit if the user enters -x flag */
if (*char == -x) {
goto remit;
else
if (*char == " ") {
goto exit;
}
/* remove carriage returns from one line /*
remit;
int main()
{
const char *remove_any_of = "\n\r";
int c;
while((c = getchar()) != EOF) {
if (!strchr(remove_any_of, c)) putchar(c);
exit;
return 0;
}
Best Regards
JacknGill 
modified 6hrs 15mins ago.
|
|
|
|
|
jackngill wrote: ...tried to compile to create ECO.COM/EXE but it is not working... What exactly does that mean?
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi David,
Many thanks for responding to my posting & yes I should of explained with more clarity in respect of my failure. This will be my first program written in "C" I usually write small batch programs in XP and/or sometimes in Win9x. I have found that CMD (although) is very good sometimes I could do with some assistance programs to ease XP's CMD. So I am trying to write small helper programs in "C" to facilitate this, just some background info which may or may not be relevant.
I have been to an online site which compiles my code as a check & a series of errors are reported which lead me to believe my code has errors & is not right I will display the output below from "https://www.onlinegdb.com/online_c_compiler"
The Compilation failed due to following error(s).
main.c:7:1: error: expected identifier or ‘(’ before ‘for’
for (i = 1; i < argc; i++) {
^~~
main.c:7:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
for (i = 1; i < argc; i++) {
^
main.c:7:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘++’ token
for (i = 1; i < argc; i++) {
^~
main.c: In function ‘echo’:
main.c:29:28: error: ‘STDIN’ undeclared (first use in this function)
while(fgets(input, 80, STDIN)){ //read from STDIN (aka command-line)
^~~~~
main.c:29:28: note: each undeclared identifier is reported only once for each function it appears in
main.c: At top level:
main.c:38:7: error: expected identifier or ‘(’ before ‘if’
if (*char == -x) {
^~
main.c:42:7: error: expected identifier or ‘(’ before ‘else’
else
^~~~
main.c:47:14: error: unterminated comment
/* remove carriage returns from one line /*
^
I am unclear as to what these errors messages mean really. Hope this gives you a rough idea as to where my failure is. I am concerned also about the structure of my potential program as I am not sure if it is right? any guidance would be appreciated? Also just as a tag-on due to the fact I am writing very small programs could you advise as to a small .com .EXE builder that I could use Please?
Best Regards
modified 18hrs ago.
|
|
|
|
|
You cannot have lines of code outside of functions in that way. Line 7 is a for statement but it cannot exist stand-alone like that, it needs to be part of some function. If you look below at function main, you can see the correct structure. I suggest you get hold of a copy of The C Programming Language - Wikipedia[^] and learn from the beginning.
|
|
|
|
|
Hi Richard,
Reading between the lines I think you are saying my code is way off base & is fundamentally wrong. would the following correct the For section like so I have removed the int main() as I am assuming only one int main() is required. your advice is duly noted in respect of ground up code writing many thanks?
/* setting flag to remove crlf */
int main()
{
for (i = 1; i < argc; i++) {
/* Check for a switch (leading "-"). */
if (argv[i][0] == '-') {
/* Use the next character to decide what to do. */
switch (argv[i][1]) {
case 'x':
printf("flag a was called\n");
break;
}
}
}
|
|
|
|
|
Yes, all code must be contained in a function. you can put it all in main for a simple program, but for more complex problems you should create other functions that can be called with different parameter values. The documentation explains it clearly.
|
|
|
|
|
Thanks Richard,
I have edited/amended my first post to reflect what you have said. Yes small programs are a good place to start
many thanks!
|
|
|
|
|
You have another function inside main, which is also wrong:
int echo(){
char input[80];
Each function must stand alone in the main part of the source file:
int echo()
{
}
int main()
{
}
And get rid of those goto statements, that is really bad practice in modern programming. As I suggested above, get a copy of K & R and spend time learning the language properly. Trying to learn by questions here will take ten times as long, and not be comprehensive.
|
|
|
|
|
Hi Richard,
Sorry for not being attentive but I have been trying to find the book that you referred to in respect of "C" programming & I have finally sourced a copy albeit in PDF format but I have none-the-less found it, so I've got it now. Also I have been viewing a u-tube video which I have downloaded from here:
https://www.youtube.com/watch?v=KJgsSFOSQv0[^]
Only because I am the type of person if I can see it visually I tend to retain the info a bit better as I am not the sharpest tool in the toolbox if you know what I mean.
The narrator in the video mentions code::blocks which comes with IDE text editor & compiler to run the programs I selected the portable version with mingw to get started I will install tommorrow & give test run I have also been listening to some of the examples on the utube video. I may be able to break my code sample down into say 3 stages and run the code in Code::Blocks to check if the code is somewhere near possibly (Test-running)?
When you refer to the goto statements as being very bad practice in modern programming the only reason I opted to use these was because batch scripting is familair ground to me & Batch uses goto :labels therein quite a lot. Also one of the web-sites stated that goto statements are bad because of the dangers of spaghetti code, however they went onto say that if used sparingly & in the case of flag usage e.g. & only confined to purely isolated cases (like flags -X) they were, (although frowned upon) were permissable.
If I could use them until I acquire the necessary alternative skillset would it be okay for now given my obvious limitations. I could then interchange the new code with the goto code at a later date or is there another reason which I am missing here that I should not be using them, like they will not compile etc?
I will also attempt to amend the 1st post code with amended curly brackets.
Best Regards
modified 6hrs 10mins ago.
|
|
|
|
|
Microsoft Visual C++ 2019. Windows 10, using MFC
Is there a nice step by step example of code showing how to use the MRU in a standard SDI application with ribbon and without document/view architecture?
My used files (*.jpg, *.bmp) are well stored in the MRU file list of the main menu of the ribbon.
But when I click on one of them I have an error in .../MFC/appui.cpp showing that ENSURE_VALID(m_pDocManager) failed, which is normal because I did not choose doc/view support.
Is there any way out, unless completely rewriting a new project with pDocManager?
Pierre
|
|
|
|
|
|
|
You are welcome!
|
|
|
|
|
Hi
I want the array of data under items, using this code i am able to get only the value under the first structure of data under items. How can i loop to the second structure of data under items, and further more if present. I am doing this using boost in c++.
Can someone help on this.
items=root.get_child("Serial");
for (boost::property_tree::ptree::iterator itprop = items.begin(); itprop != items.end(); ++itprop)
{
for(boost::property_tree::ptree::iterator it1=itprop->second.begin();it1!=itprop->second.end();++it1)
{
if(it1->first=="Items")
{
boost::property_tree::ptree& rootschild=it1->second;
cout<<"Size is "<<rootschild.size()<<"\n";
for(boost::property_tree::ptree::iterator="" it2="rootschild.begin();it2!=rootschild.end();++it2)
" {
="" it3="it2-">second.begin();it3!=it2->second. end();++it3)
{
std::cout<<it3->first<<": "<<it3->second.get_value<string>()<<"\n";
}
}
}
{
"Header": {
"Name": "abcd",
"Email": "xyz"
},
"Serial": [{
"flavour": "Green",
"Color": "9",
"code": "103",
"Items": [{
"date": "2020/11",
"value": "3.5",
"serial": "01"
}, {
"date": "2020/10",
"value": "3.4",
"serial": "03"
}]
}]
}
With Regards
|
|
|
|