|
Your CMyView object should be a member of the CMainFrame , so you just need to add a public method to CMyView that does what you want.
modified 1-Jan-21 6:55am.
|
|
|
|
|
Dear Friend
I did it,Because it seemed very easy, but then I get CDocument ERROR!
After adding #include "CMyView.h" into CMyMainFrame, I get CDocument ERROR!
I searched a lot on the internet, all say use GetActiveView() but it does not work!
Best Regards
|
|
|
|
|
Sorry, we cannot guess what you are doing. You need to show the code that that you are running, and explain exactly what error(s) you see and where it happens.
|
|
|
|
|
Dear friend
I write the following code inside MyCMainFrame.cpp file :
MyCView*pView = static_cast<mycview*> (GetActiveWindow());
pView->m_CMyView_Pulic_Variable;
To get access to public variables inside CMyview class.
But when I include MyCView.h file inside MyCMainFrame file to use GetActiveView(), then I get CDocument ERROR!
In fact, I just want to change a public variable inside CMyView class from MyCMainFrame.
How can I get access to CMyView class public variables, from MyCMainFrame?
Best Regards
|
|
|
|
|
Why are you using GetActiveWindow rather than GetActiveView ? And what is the exact text of the error you receive and where does it occur?
|
|
|
|
|
Dear Richard
Firstly "HAPPY NEW YEAR"
Many thanks for your help, I was engaged with the CMyDoc error, finally I found it, simply it was redefinition of CMyDoc header in 2 different classes that I never guessed such mistake.
Best Regards
|
|
|
|
|
Glad you found it. Happy New Year (as much as it can be) to you also.
|
|
|
|
|
|
|
Nobita and String | Basics of String Manipulation & Algorithms Practice Problems | HackerEarth[^]
this is the question. my code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
std::string s[t];
for(int i=0;i<=t-1;i++)
{
string st;
getline(cin,st);
int l=(int)st.length();
string s2="",s3="";
for(int i=0;i<=l;i++)
{
if(st[i]==' '||st[i]=='\0')
{
s3=s2+" "+s3;
s2.clear();
}
else
{
s2+=st[i];
}
}
s[i]=s3;
}
for(int i=0;i<=t-1;i++)
cout<<s[i]<<endl;
return 0;
}
the error message is saying " your program doesnt print anything. can anyone help me find whats wrong?
|
|
|
|
|
for(int i=0;i<=l;i++)
Try changing to
for(int i=0;i<l;i++)
You're index is going out of bounds on the st variable 'st[i]', when i is equal to l.
Also, having nested for loops with the same index variable name is tough to read.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
After the following line
cin>>t;
there are still charactes in the input buffer, hence, the next call to getline gets them.
A commont way to deal with this issue is using cin.ignore (see, for instance What is the use of cin.ignore() in C++?[^]).
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Have you tried stepping through the code using a debugger? Doing so will let you know in a hurry what is wrong.
"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
|
|
|
|
|
In addition to other answers.
Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
std::string s[t];
for(int i=0;i<=t-1;i++)
{
string st;
getline(cin,st);
int l=(int)st.length();
string s2="",s3="";
for(int i=0;i<=l;i++)
{
if(st[i]==' '||st[i]=='\0')
{
s3=s2+" "+s3;
s2.clear();
}
else
{
s2+=st[i];
}
}
s[i]=s3;
}
for(int i=0;i<=t-1;i++)
cout<<s[i]<<endl;
return 0;
}
Indentation style - Wikipedia[^]
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
Enabling Open Innovation & Collaboration | The Eclipse Foundation[^]
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Hello,
I am trying to draw an image (2nd image) over the other image (existing image file - 1st image) using gdi+ bitmap and graphics and then saving (overwriting) the same 1st image file. But saving is not getting done, when i use GetLasError(), it shows error message,
"The process cannot access the file because it is being used by another process"
Here is the code what i am doing.
<pre>Gdiplus::Bitmap *gpBitmap = new Gdiplus::Bitmap(mImagePath1); Gdiplus::Graphics *gr = Gdiplus::Graphics::FromImage(gpBitmap);
Gdiplus::Bitmap img(mImagePath2); Gdiplus::Bitmap* pThumbnail = static_cast<Gdiplus::Bitmap*>(img.GetThumbnailImage(32, 32, NULL, NULL));
gr->DrawImage(pThumbnail, newWpos, newHpos);
Gdiplus::Status stat = gpBitmap->Save(mImagePath1, pClsid);
I tried making copy also, but same issue.
please suggest.
Regards,
Gopi.
|
|
|
|
|
Your file mImagePath1 is still open to the Bitmap object. You should use a different path to save the new image.
|
|
|
|
|
Thank you Richard.
This helps me to solve my issue.
Regards,
Gopi.
|
|
|
|
|
In Visual C++ 2012 I have written this code:
strstream& operator>>(strstream& Stream,CComponent* pCmp){
..code
}
std::strstream read_file((char*)filbuf,file_size,ios_base::out);
pComp=new CComponent;
read_file>>pComp;
This works perfectly. But when I run it on my newly installed Visual C++ 2019 it compiles all right, but the output is wrong.
I see that std::strstream is deprecated, but it should still function. If I try to put std::stringstream instead, it will not accept the >> operator.
|
|
|
|
|
Haakon S. wrote: it compiles all right, but the output is wrong. You need to explain what that means.
|
|
|
|
|
Ok, some details. Everything seems to be identical when I check the debug data. The text file is referenced in the same way by filebuf.
The first member of CComponent is specified as WORD m_nNo and the this value in the first component is 56.
I put some test code on top of my function to try to find out what is going on.
std::strstream& operator>>(std::strstream& Stream,CComponent* pCmp){
char txt[4];
Stream >> txt;
.
.
.
}
The watch window displays the following output from the new C++ version:
- txt 0x00cfd5fc "" char[4]
[0] 0 '\0' char
[1] -52 'Ì' char
[2] -52 'Ì' char
[3] -52 'Ì' char
From my older version I get the correct output:
- txt 0x0055e25c "56" char[4]
[0] 53'5' char
[1] 54'6' char
[2] 0 '\0' char
[3] -52 'Ì' char
It seems that the extraction operator >> simply does not work anymore. In that case, what is the best alternative for reading data from a text file. If I replace strstream with stringstream I get the message that stringstream does not have a >> operator.
modified 23-Dec-20 4:35am.
|
|
|
|
|
If you are reading from a file then you should be using one of the fstream classes.
|
|
|
|
|
Looks to me like it is the *old* version that wasn't working: your code overwrites your text variable, so why would you expect it to still hold the old value? Or maybe it is just that the VS2012 debugger didn't show these contents properly because it didn't recognize that you were writing to it.
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)
|
|
|
|
|
First, stringstream is not strstream. You may need to specifically use ostringstream instead. But anyway, like Richard already stated, you should be using fstream, or ofstream.
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)
|
|
|
|
|
Hi.
Thanks for helping.
ifstream accepts the >> operator and get() function.
std::ifstream read_file((char*)filbuf,file_size,ios_base::out);
.
.
pComp=new CComponent;
read_file>>pComp;
This function is called:
ifstream& operator>>(ifstream& Stream,CComponent* pCmp){
Stream>>pCmp->m_nNo;
Stream.get(pCmp->m_formula,15);
.
.
}
Everything works fine, except that nothing is actually read.
Regards, Haakon.
|
|
|
|
|
Haakon S. wrote: Everything works fine, except that nothing is actually read
Well both of those statements cannot be true.
|
|
|
|