|
Hi friends! I am new to c++ and just went through the concept of Namespace.What I have understood about namespace till now is that "it is a region where identifiers can be declared in form of group".
But then I went through the following code somewhere on internet
Namespace identi
{
int a;
Class S
{
public:
int z;
float x;
}
}
So I am bit confused after seeing the definition of class S inside namespace.isn't it only a declarative region where we can only declare identifiers together in a group or can we define identifiers as well inside it? Just like we did with class S.Kindly someone please answer, would be so nice of you.
|
|
|
|
|
|
the main reason of why we use namespace identifier is classify our code in a bigger categories and parts. its useful to manage your libraries by "using namespaces". Imagine you can have many different name spaces in your code and every time you need you can use it. its helps you to choose smaller and more abstract names for your classes and functions.
for example you can have many Mathematic function and classes in a namespace like "Matrix". in that case you can have simple function names like "add" , "div", "mul" instead of "matrix_add" ,"matrix_dev" and ...
to use them in an specific part of your code you can use it in to ways ..
1:
Matrix.add(m1,m2);
Matrix.div(m3,m4);
2:
using Matrix {
add(m1,m2);
div(m3.m4);
}
also for defining classes and functions in a namespace you can do it like this ...
namespace Matrix {
void add(matrix a, matrix b){
...
}
void div(matrix a, matrix b){
...
}
void mul(matrix a, matrix b){
...
}
.
.
.
}
|
|
|
|
|
It seem like I remember that rich edit used to line break on CR/LF 0x0d + 0X0D now it seems either 0x0a 0x0c (form feed) of 0x0d (carriage return causes) causes a line break
Is there a way to look for a specific version of rich edit I means the class names for 1.0 thru 3.0 the doc says use RICHEDIT_CLASS which loads Riched20.dll
more so I remember that rich edit would only line break on CR AND LF not sure which version as I would like to use that version
|
|
|
|
|
|
Hi
here is my wordbreak function
int CALLBACK EditWordBreakProc(LPTSTR lpszEditText, int ichCurrent, int cchEditText, int code)
{
char FAR* lpCurrentChar;
int nIndex;
int nLastAction;
switch (code)
{
case WB_ISDELIMITER:
if (lpszEditText[ichCurrent] == 0x0a0d)
return TRUE;
else
return FALSE;
break;
}
}
Here is where I invoke it
fptrx = &EditWordBreakProc;
storagepointer->SendMessage(EM_SETWORDBREAKPROC, 0,(LPARAM) fptrx);
long numstream = storagepointer->StreamIn(SF_TEXT,STORAGESTREAM);
variable definition
funcptrx fptrx;
int CALLBACK EditWordBreakProc(LPTSTR lpszEditText, int ichCurrent, int cchEditText, int code);
typedef int (CALLBACK *funcptrx) (LPTSTR, int, int, int);
|
|
|
|
|
I am writing code in standard C for a microcontroller (STM32L) and I compile with GCC. I have a struct that contains a union and the union can be of different size:
struct MyStruct
{
int someInteger;
union
{
int smallMember[1];
int bigMember[1000];
} smallOrBigMember;
}; Is it possible for me to declare an object of MyStruct that only occipies 8 bytes of memory if I only intend to use the smallMember of that object?
|
|
|
|
|
No, you cannot. If you need a flexible size structure, the idiomatic solution is to add a zero size array at the end of the structure. Then, presumably, one of the fixed length fields tells you the size of the variable part. Something like this:
struct MyStruct
{
int small_or_big;
int variable_part[0]; };
struct MyStruct *ptr;
if (ptr->small_or_big == BIG_STRUCT)
{
ptr->variable_part[999] = some_value; }
When you allocate the structure you have to account for the variable part:
ptr_small = malloc(sizeof(MyStruct) + SIZE_OF_SMALL_PART);
ptr_small->big_or_small = SMALL_STRUCT;
ptr_big = malloc (sizeof(MyStruct) + SIZE_OF_BIG_PART);
ptr_big->big_or_small = BIG_STRUCT;
Mircea
modified 6-Mar-22 11:10am.
|
|
|
|
|
I have been using carriage return 0X0AD line feed 0A to break lines on Rich Edit using SF_TEXT until I noticed some of the data I am trying to Dump contains a 0x0d 0X0A causing an inadvertent line break
is there an another way to break lines
Thanks
|
|
|
|
|
I think what you need to do is find another way to represent the 0xAD data so that it doesn't trigger a line break. Like use a special character to represent it in the data stream that you're loading into the control.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I thought rich edit uses BOTH CR / LF as new line seems different versions Of Richedit now to 4.1 have different methods of line breaking trying to figure which rich edit dll/class version I am running
|
|
|
|
|
Write a C++ program that reads a positive integer n, and prints the first
n even numbers.
For example, one execution would look like this:
Please enter a positive integer: 3
2
4
6
File Name
evennumbers.cpp
Score
There are three tests each worth 2 points
1.#include<iostream>
2.using namespace std;
3.
4.int main()
5. {
6. int n;
7. cout<<"Please enter a positive integer:";
8. cin>>n;
9.
10. cout<<"These are all even numbers in between 1 to "<
|
|
|
|
|
Well, looks like good and not complicated exercise. Did you solve it?
|
|
|
|
|
Hi it's okay when I run it,but the Autograrder says FAILED.What could be the problem? Should I submit the executable file only.If I rename the executable file as .cpp the Autograder results to errors of 2 .cpp files.What should I do please?
|
|
|
|
|
Sorry, I could not understand what you mean...
The code you've posted is not complete, it doesn't compile and it does nothing.
|
|
|
|
|
Hi it's okay when I run it,but the Autograrder says FAILED.What could be the problem? Should I submit the executable file only.If I rename the executable file as .cpp the Autograder results to errors of 2 .cpp files.What should I do please?
|
|
|
|
|
Please, stop reposting the same!
I've already read it (your post from 1-Mar-22 9:33) And answered!
|
|
|
|
|
How do you expect anyone here to answer? We have no idea what the Autograrder is, or what criteria it uses to judge your code. And unless you show the complete code we cannot suggest any changes.
|
|
|
|
|
So what's the problem, exactly?
"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
|
|
|
|
|
Is there any doubt? He wants someone to do his work.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
#include<stdio.h>
int getFactorial(int);
int main(void) {
int n;
printf("Enter n: ");
scanf("%d",&n);
printf("Factorial of %d is %d", n, getFactorial(n));
return 0;
}
int getFactorial(int n) {
}
|
|
|
|
|
Christine Belisario wrote: // how to Implement this recursive function Google will find you many explanations of the factorial function. You just need to think about how you could implement it in code.
|
|
|
|
|
When you've got a plank of code like this, and haven't necessarily begun stepping a mast of methods by leafing through your function library, presumeably squirreled away in the hold in a rat-free database, sometimes it's best to just go to a search engine that's got three sheets to the wind (open to the public), type in each word grain separated by commas and hammer the return.
And marking the returns using your favorites folder by hanging the list of code fragments off the hook of the internet browser you're buckling, for future reference, you're well on your way to driving the sea with your bark of ... lively functions ... and saving CP from a dumb trend which is hopefully on it's way south.
|
|
|
|
|
Prize winner for metaphor density.
|
|
|
|
|
first of all, i shall thanks all of you guys.
In my project, i created some STATIC & EDIT controls in a CDialog and set these control's parent to a group box(also a STATIC control).
it works well for create, but it can't be delete dynamically.
For example, i create 5 EDIT control then delete it(there are no sub-controls in group box this time), and i create 2 EDIT control again, oops! there are 5 EDIT control showing in the group box. So, i guess this caused by the group box haven't refreshed in time. and then i sendmessage to group box to force it to refresh. unfortunately it doesn't works.
here is my code:
<pre lang="C++">
void CPLCDlg::DynamicCreateEdit(UINT nNums)
{
const int YSpace = 15;
const int EHeight = 20;
const UINT EDITID = 72000;
if (nNums <= 0)
return;
CButton* pGroup = (CButton*)GetDlgItem(IDC_STATIC_GROUP);
if (NULL != pGroup)
{
if (NULL != m_pDynEdit && m_siNumsOfDynEdit > 0)
{
for (short i = 0; i < m_siNumsOfDynEdit; i++)
{
if (NULL != m_pDynEdit[i].GetSafeHwnd())
{
m_pDynEdit[i].ShowWindow(SW_HIDE);
m_pDynEdit[i].DestroyWindow();
}
delete m_pDynEdit[i];
}
delete[] m_pDynEdit;
m_pDynEdit = NULL;
::SendMessage(pGroup->GetSafeHwnd(), WM_ERASEBKGND, 0, 0);
}
pGroup->Invalidate(FALSE);
pGroup->RedrawWindow();
pGroup->UpdateWindow();
CRect rcPos;
CString str;
rcPos.SetRectEmpty();
m_pDynEdit = new CEdit[nNums]();
for (short i = 0; i < nNums; i++)
{
rcPos.left = 10;
rcPos.top = 20 + (EHeight + YSpace) * i;
rcPos.right = rcPos.left + 30;
rcPos.bottom = rcPos.top + EHeight;
str.Empty();
str.Format(_T("%d"), i + 1);
if (m_pDynEdit[i].CreateEx(WS_EX_STATICEDGE, _T("EDIT"), (LPCTSTR)str, ES_CENTER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, rcPos, pGroup, EDITID + i))
{
//m_pDynEdit[i].SetWindowText(_T("0"));
}
}
m_siNumsOfDynEdit = nNums;
}
}
</pre>
|
|
|
|