|
It should reach that point, you stated it works if you remove the flag, right?
Veni, vidi, vici.
|
|
|
|
|
Overloaded_Name wrote: if(IsItemNumEven)
Why don't you look at pLVCD->nmcd.dwItemSpec instead?
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
i want the user give me number.and i will setup queue with this number of zero.(case e) i get error to copile and i dont know why.
#include <iostream>
#include <list>
#include <deque>
using namespace std;
char option()
{
char c;
cout<<"A push valu\n"; cout<<"B pop valu\n"; cout<<"C the first valu in list\n"; cout<<"D is empty\n"; cout<<"E build queue\n";
cout<<"F print list\n"; cout<<"G print queue\n";
cout<<"H exit\n";
cout<<"selecte:";
scanf("%c",&c);
return c;
}
void main()
{
typedef deque<int> j;
list<int> v;
list<int>::iterator i;
int x;
char c;
do
{
c=option();
switch(c)
{
case 'a':
cout <<"enter number:";
cin >> x ;
v.push_back(x);
cout << endl;
flushall();
break;
case 'b':
if(v.empty())
cout<<"the list empty\n"<<endl;
else
{
v.pop_back();
cout <<"pop form back done\n"<<endl;
}
flushall();
break;
case 'c':
if(v.empty())
cout<<"the list empty\n"<<endl;
else
{
i=v.begin();
cout<<*i<<endl;
}
printf("\n");
flushall();
break;
case 'd':
if(v.empty())
cout<<"the list empty\n"<<endl;
else cout <<"there is somting in the list\n"<<endl;
printf("\n");
flushall();
break;
case 'e':
int numbers;
cout<<"how many number you want in queue:";
cin >> numbers;
j a(numbers,0);
printf("\n");
flushall();
break;
case 'f':
for (i=v.begin(); i != v.end(); ++i)
cout << *i << " ";
cout <<"\n"<< endl;
flushall();
break;
case 'g':
printf("\n");
flushall();
break;
case 'h':
cout <<"bye\n"<< endl;
exit(1);
default :
cout <<"no such option\n"<< endl;
flushall();
break;
}
}while(c!='h');
}
|
|
|
|
|
You need to explicitly scope variables created inside a case statement.
So case 'e' must look like this (with braces) -
case 'e':
{
int numbers;
cout<<"how many number you want in queue:";
cin >> numbers;
j a(numbers,0);
printf("\n");
flushall();
}
break;
|
|
|
|
|
That would be correct, but probably useless.
Veni, vidi, vici.
|
|
|
|
|
thanks very helpful but now i have problem to print (case g)
#include <iostream>
#include <list>
#include <deque>
using namespace std;
char option()
{
char c;
cout<<"A push valu\n"; cout<<"B pop valu\n"; cout<<"C the first valu in list\n"; cout<<"D is empty\n"; cout<<"E build queue\n"; cout<<"F print list\n"; cout<<"G print queue\n";
cout<<"H exit\n";
cout<<"selecte:";
scanf("%c",&c);
return c;
}
void main()
{
typedef deque<int> j;
deque<int>::iterator p;
list<int> v;
list<int>::iterator i;
int x;
char c;
do
{
c=option();
switch(c)
{
case 'a':
cout <<"enter number:";
cin >> x ;
v.push_back(x);
cout << endl;
flushall();
break;
case 'b':
if(v.empty())
cout<<"the list empty\n"<<endl;
else
{
v.pop_back();
cout <<"pop form back done\n"<<endl;
}
flushall();
break;
case 'c':
if(v.empty())
cout<<"the list empty\n"<<endl;
else
{
i=v.begin();
cout<<*i<<endl;
}
printf("\n");
flushall();
break;
case 'd':
if(v.empty())
cout<<"the list empty\n"<<endl;
else cout <<"there is somting in the list\n"<<endl;
printf("\n");
flushall();
break;
case 'e':
{
int numbers;
cout<<"how many number you want in queue:";
cin >> numbers;
j a(numbers,0);
printf("\n");
flushall();
}
break;
case 'f':
for (i=v.begin(); i != v.end(); ++i)
cout << *i << " ";
cout <<"\n"<< endl;
flushall();
break;
case 'g':
for (p=a.begin(); p != a.end(); ++p)
cout << *p << " ";
cout <<"\n"<< endl;
flushall();
break;
case 'h':
cout <<"bye\n"<< endl;
exit(1);
default :
cout <<"no such option\n"<< endl;
flushall();
break;
}
}while(c!='h');
}
|
|
|
|
|
You should really give better descriptions of the errors.
However, in this case, the problem is that a variable has limited scope and case 'g' cannot see it (already destroyed).
You better declare a (using default constructor) before entering the switch block and then populate it in case 'e' .
Veni, vidi, vici.
|
|
|
|
|
You must include stdio (use #include <cstdio> ) in order to use scanf , printf , etc.
Veni, vidi, vici.
|
|
|
|
|
Woa there Tex! Three are the things that jump out at me reading your code:
- switch statement from hell. At least call a function per case statement rather than piling all your code in one place
- mixing cstdio with iostream . Don't do it unless you're an expert. If you are an expert think twice about why you need to mix them.
- don't bother using exit(n); in main . return n; has the same effect.
The error you're getting is going to be something like "initialization of variable is skipped by switch statment." What that means is if someone enters 'f', 'g', 'h' the constructor for a won't be called. The flow of control goes galloping past, jumping over the initialisation of a. In your case this isn't a problem as a isn't used elsewhere. To get around this either stick everything that's currently in a case statement in a function OR use an additional level of scope around your case statement. I'd go for functions personally as scoped cases can get a bit ugly:
case 'e':
{
int numbers;
cout<<"how many number you want in queue:";
cin >> numbers;
j a(numbers,0);
printf("\n"); flushall();
break;
}
break;
Anyway, hope that helps. If not shout and we'll see what we can do to improve our answers.
Edit: Realised that I'd said the wrong set of case statements avoided calling the constructor. Hopefully corrected that now!
modified 29-May-12 6:37am.
|
|
|
|
|
tanks for the comments and sorry about my english
i fix the problem by putting the print function in the same case, my Q is why with the tamplate list i have larg scope and with deque i have to be in the same case ?
|
|
|
|
|
a1_shay wrote: ...and i dont know why.
Neither do we. What is the compiler error you're seeing?
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi All,
Could anyone tell me how to integrate cxxTest with VS IDE? i am very new for the cxxTest so if you provide the procedure with all steps then it would be appreciable.
i followed the steps given in the link below but its not working. i might be doing some mistake. please help me.
http://morison.biz/technotes/articles/23[^]
I am waiting for ur valuable reply.
Thanks in advance
|
|
|
|
|
Have you got Python[^] installed? Aside from getting a copy of Python the notes looks fairly complete.
|
|
|
|
|
thanks for the reply.
yes i have installed Python 2.7 in my system. Even though not getting runner.cpp file.
|
|
|
|
|
hello guys... I am trying to write a simple library (in C++, for learning purpose) which is platform independent and can run on at least Windows and Linux (Ubuntu/Fedora).
Now I am using VS 2010. Can anyone guide me that how can I use this library on Linux and using which IDE?
Now if this approach has issues, can you guide that which IDE should I use (Eclipse may be?) on windows which will also work on Linux. Thanks for any pointers.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Gday mate,
I used Eclipse years ago for developing Flex apps and was unimpressed. I picked it up again earlier this year when I played with android development but alas, again I was disappointed by the less than stellar performance. Damn you Java!
I'd be inclined to used Code::Blocks, it's compiled to native code, its available Win / Linux / Mac, 32 & 64 bit, will happily work with about a dozen or more compilers.
Also, without knowing the nature of the library it's impossible to know if this is a consideration or not, however - Code::Blocks has built-in support for using WxWidgets, which vastly eases the development of GUIs that are immediately portable.
It's also quite a small download - ~70MB for the IDE and GCC combined. Certainly worth a look imho.
|
|
|
|
|
Writing a platform independent library is fairly easy - don't use any features of the OS' you're targeting and don't make any assumptions about data sizes, object layout and anything else that the standard says is undefined.
If you're happy developing on Windows then don't bother with an IDE for Linux. Do all your development on Windows, checking at least once a day that everything builds using gcc. When I do cross platform development I use VC++2010 and gcc from mingw to make sure it builds. I've yet to write code I intended to be portable that didn't run on Linux that compiled on gcc from mingw.
For controlling the build I'd suggest one of three things:
- If your library is really small stick the g++ command line in a shell script and run that. Really small is a couple of source files.
- If your library is a bit bigger then write a makefile. mingw comes with two versions of make, both of which have (for simple projects) the same behaviour on Linux. I'd use this for libraries up to about 20 source files that you only want to build and run on a couple of platforms
- If your library is effing huge (10s of source files) and you want it to build and run on just about every Unixy platform on the planet use GNU autotools[^]. This is a set of (rather complicated) but very flexible tools that by writing a couple of simple files lets you build, test and run your code on loads of different platforms. I've used them to run code code I wrote on VC++ for windows on Linux, FreeBSD (both 32 and 64 bit) and Solaris.
Whatever you use I'd suggest eventually looking at the autotools if you ever want to do any cross platform stuff. They're pretty ubiquitous in the GNU world - whenever you ./config a package on Linux you're using them.
Oh, one thing I forgot to mention up top... If you need stuff usually supplied by the OS have a dig around for a library that already does it. Three libraries I use a lot are boost [^](it's a test bed for new libraries that might be standardised one day and has sorts of useful stuff - I've used it for date/time, filesystem support, threads, interprocess comms, shared and unique pointers before were in the standard), OpenSSL [^](all your crypto needs admittedly with the most bent interface you've ever seen) and libcurl [^](everything for HTTP/FTP/GOPHER client development).
|
|
|
|
|
Is there such a thing as a program that watches to make sure another program is running OK, and if it crashes, restarts it?
What is the preferred mechanism by which such a thing would be implemented?
(Not asking for code, just some ideas)
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
This is usually done by having a Windows service that watches over your program.
There are several such programs available - Search for Application Watchdog[^]
Windows from Vista onward also supports Application Recovery and Restart[^] that you can use to have Windows restart your application in case of an unhandled exception.
|
|
|
|
|
Thanks, Superman.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Developing whatch dog on windows is very easy, all you need to create a named mutex from the process (program) needed to moniter, and from your moniter process, wait for that mutex handle to be closed. If it get closed than restart your program.
If you are a Linux user than crontab is your friend, use crontab instead of develop new watchdog so that you can spent time to find out why you program is crashing.
On windows you can use cronw.
Good Luck.
|
|
|
|
|
Hi,
Is anyone aware of a 'Task Manager Logging' App that can 'Capture and Record' most or all of the information viewable in Task Manager, sampled at regular intervals, in some form of Database. One of our clients experiences quite extensive memory leaks in Windows XP. We are confident that it is not our software, but it is a case of 'It only started happening after your stuff was installed' We would like to run something that takes a SnapShot, Starters say every fifteen minutes, and upon notifyable events, such as Process Starts or Stops.
Alternatively, is there a way to configure 'MS Windows Event Logging' to do the same.
I am just trying to figure out Why this customer gets 'Low virtual Memory' messages after two or three days running, and the system grinds to a Halt when that happens.
Regards,
Bram
Bram van Kampen
|
|
|
|
|
|
You could use Process Explorer[^].
Be sure to apply appropriate filters for logging because it does some extensive logging and could soon fill up your hard disk.
|
|
|
|
|
Thanks
This seems to fit the bill.
Regards,
Bram van Kampen
|
|
|
|