Hot Topic (More than 10 Replies) C++ (Read 6419 times)
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
C++
Apr 13th, 2007 at 8:05pm
Print Post Print Post  
I'm studying C++ and in my book they use the following "std::end1" but I have two C++ compliers and both give me errors that end1 is no part of std, have they replaced it with something else I should use ??  Undecided
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: C++
Reply #1 - Apr 13th, 2007 at 8:23pm
Print Post Print Post  
proudpoppy wrote on Apr 13th, 2007 at 8:05pm:
I'm studying C++ and in my book they use the following "std::end1" but I have two C++ compliers and both give me errors that end1 is no part of std, have they replaced it with something else I should use ??  Undecided


I suspect that that is endl (with a lower case "L" at the end of end) not end1. It represents end-of-line.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: C++
Reply #2 - Apr 13th, 2007 at 8:34pm
Print Post Print Post  
may need to clean my glasses !  Grin Must be a misprint in the book the number 1 and the 1 at the end1 is identical, it does respresent end of line.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: C++
Reply #3 - Apr 13th, 2007 at 8:48pm
Print Post Print Post  
Do you already know C (as opposed to C++)?
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: C++
Reply #4 - Apr 14th, 2007 at 3:04am
Print Post Print Post  
Quote:
Do you already know C (as opposed to C++)?

No, I bought the Book C++ 4th edition How to program by Dietel, Had it for several month just decide to open it, most of my programming experience is in Pascal, and Visual Basic. Can't comment to much right now just on page #28 but you got to start somewhere.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: C++
Reply #5 - Apr 14th, 2007 at 3:26am
Print Post Print Post  
As you may have heard, all of Sesame is written in C/C++. We lean heavily towards C and only use a small portion of the C++ exclusive features. For example, we use classes and objects heavily, but barely use any overloaded operators or C++ I/O streams. Basically we use the C++ object system as a structural/design element and use chiefly C constructs down in the trenches - if you know what I mean.

If there is anything I can do to help you pick it up, let me know.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: C++
Reply #6 - Apr 14th, 2007 at 2:35pm
Print Post Print Post  
Code
Select All
#include	  <stdio.h>

char *a[] = {
	  "Learning",
	  "will",
	  "you",
	  "understand"
};

char *b[] = {
	  "SBasic.",
	  "better",
	  "help",
	  "C/C++"
};

int     main()
{
int     loop;

	  for(loop = 0;loop < 4;loop++)
	  {
		    printf("%s %s ", a[loop], b[3 - loop]);
	  }
	  printf("\n");
	  return(0);
}
 

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: C++
Reply #7 - Apr 14th, 2007 at 4:14pm
Print Post Print Post  
Shouldn't this:

Code
Select All
char *a[] = {
	  "Learning",
	  "will",
	  "you",
	  "understand"
};

char *b[] = {
	  "SBasic.",
	  "better",
	  "help",
	  "C/C++"
}; 



be this:

Code
Select All
char *a[] = {
	  "Learning",
	  "will",
	  "you",
	  "understand"
};

char *b[] = {
	  "SBasic.",
	  "help",
	  "better",
	  "C/C++"
}; 

?
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: C++
Reply #8 - Apr 14th, 2007 at 6:28pm
Print Post Print Post  
Bob,

Not if you want the output to follow english word order.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: C++
Reply #9 - Apr 14th, 2007 at 8:53pm
Print Post Print Post  
I thought that your version would translate to:
"Learning SBasic will better you help understand C/C++

And I thought my version would translate to:
"Learning SBasic will help you better understand C/C++"

=============

I have not used C/C++ so I was trying to do some intuitive compiling.  I guess I will have to read a book now.

Taking a closer look, it seems that the "b" is based on (3-loop) which would translate to 3,2,1,0.  Are those a/b strings indexed starting at 0? If not, how is a negative handled for that last "b" ?




  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: C++
Reply #10 - Apr 14th, 2007 at 9:01pm
Print Post Print Post  
Bob_Hansen wrote on Apr 14th, 2007 at 8:53pm:
I thought that your version would translate to:
"Learning SBasic will better you help understand C/C++

And I thought my version would translate to:
"Learning SBasic will help you better understand C/C++"


I saw that that was what you were after. But, even then I can't agree. Learning a high level language like SBasic doesn't help much in learning a low level language like C, or an object oriented language like C++.

Quote:
=============

I have not used C/C++ so I was trying to do some intuitive compiling.  I guess I will have to read a book now.



Be glad I didn't throw in any complicated pointer arithmatic.

Code
Select All
*(**n)++ = (Money *)*ptr.resolve()->n++
 



Quote:
Taking a closer look, it seems that the "b" is based on (3-loop) which would translate to 3,2,1,0.  Are those a/b strings indexed starting at 0? If not, how is a negative handled for that last "b" ?


I obfuscated it a little so Proud Poppy would run it through his C compiler. Yes, C and C++ index arrays starting at zero.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: C++
Reply #11 - Apr 15th, 2007 at 12:33am
Print Post Print Post  
So, with an index of 0, and b(3-loop), your original example translates to:
"Learning C/C++ will help you better understand SBasic", is that correct?

That is a big difference.
======================
And high level vs. low level reminds me of many years ago when I had to program at assembly level language using hexadecimal code, throwing 16 toggle switches, and pushing a Send Button to add the instruction to the memory stack, then repeating the process again for the next instruction of 16 binary bits.  Aargh!  Glad I don't have to do that any more.  We had transistors them, in between relays and integrated circuits.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: C++
Reply #12 - Apr 15th, 2007 at 12:49am
Print Post Print Post  
Bob_Hansen wrote on Apr 15th, 2007 at 12:33am:
So, with an index of 0, and b(3-loop), your original example translates to:
"Learning C/C++ will help you better understand SBasic", is that correct?


Yah.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: C++
Reply #13 - Apr 15th, 2007 at 1:37am
Print Post Print Post  
Thanks for the help Mark

Now I C.   Roll Eyes

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: C++
Reply #14 - Apr 15th, 2007 at 2:24am
Print Post Print Post  
I do have a question, the Microsoft Visual C++ that came with the book, displays programs in a command window, and ask you to press any key to close, the dev c++ program seems to do the same thing only it just flashes the command box on the screen so fast you can't see it, how can I get the window to pause long enough to see the output? I don't believe I ever be a c/c++ programmer I get lost after 20 lines of code  but I enjoy learning and challanges but I was thinking anything I can learn would help with Sbasic programming. So far c/c++ makes more sense to me than any other programming languages I've used in the past. I have amazed myself in the past with what I could do, just looking at the application I have in Sesame its hard to believe I created it, "with a lot of help from here" A wise man said years ago, if  he can find a book on it he can do it, I was fifteen at the time and I believed him, I've read alot of books. Wink
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: C++
Reply #15 - Apr 15th, 2007 at 4:42am
Print Post Print Post  
It sounds like the microsoft "console window". This is a window that appears when running MS programs that write output to "standard output" and have console mode enabled. The console window will remain on the screen for as long as your program continues to run. So what you are probably seeing is your program writing some text to "standard output" and then exiting. To keep the window around longer you need to keep your program running longer. There are two typical ways to do that. One is you could simply force your program to wait a while, using using a Sleep command (Sleep(milliseconds) or sleep(seconds)) or put in a busy loop. A busy loop simply runs up an integer doing nothing: for(n = 0;n < 100000000;n++); The other thing you could do is get some blocking input going, which sounds like what the book wants with "hit any key to continue". In C this would be something like c = fgetc(stdin) or fgets(buf, 255, stdin).

I am very happy to hear that you are actively seeking out new things to learn. I hope that C and C++ are to your liking. If you have already picked up Pascal, C should follow somewhat similarly. They are both really in the same family, though C is lower level and relies much more heavily on operators than does Pascal. The biggest differences might be that C is not as strict about structure and has pointers. C++, on the other hand, is quite different from Pascal in that it is nominally an "object orientated" language. It introduces classes, overides, templates, and much else that are not in straight procedural languages like C and Pascal.

It sounds like your book is headed towards Windows programming (in that it provides MS Visual C++). You may want to keep going in that direction, but it will be harder to help you in that MS does things very differently than a normal C/C++ compiler and does not rigorously stick with standards (not K&R, Stroustrup, ANSI, or POSIX). You might consider some of the free compilers available for Windows, such as Digital Mars C/C++. Or, use the C/C++ compiler that is the defacto standard on Linux: gcc and g++ - the gnu compiler. Using a command line driven compiler will eliminate the need to worry about Window's console window and other oddities only associated with MS programs and programming environments.

Even when we build Sesame on Windows, we don't use the Visual environment. We use the MS compiler from the command line. That allows us to write debug out to the command line window that invoked the program, without having the program opening its own "concole window". It also is, in my opinion, a more reasonable environment than MS's IDE. I'm not sure how comfortable you are with the command line in Windows or in Linux, but I much prefer to have multiple command line windows open, than to mess around with pulldowns and dialog boxes.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: C++
Reply #16 - Apr 15th, 2007 at 6:26am
Print Post Print Post  
ProudPoppy, check this out: http://groups.google.com/group/microsoft.public.win32.programmer.gdi/browse_thre...

It suggests adding a Pause or GetChar at the end of the code, forcing a pause for input.

system("PAUSE");

OR

getchar()
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: C++
Reply #17 - Apr 15th, 2007 at 4:26pm
Print Post Print Post  
Thanks Mark & Bob, I'm using a c++ compiler from www.bloodshed.net, along with the one from the book.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: C++
Reply #18 - Apr 15th, 2007 at 4:30pm
Print Post Print Post  
proudpoppy wrote on Apr 15th, 2007 at 4:26pm:
Thanks Mark & Bob, I'm using a c++ compiler from www.bloodshed.net, along with the one from the book.


My, what a gruesome sounding URL for such a benign appearing website.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: C++
Reply #19 - Apr 15th, 2007 at 4:59pm
Print Post Print Post  
In any case, if you run a program that writes to standard output, from a command line (instead of from an icon or menu, etc...), it shouldn't have to open a console window. It will simply print in the command line window from which it was opened. So no need for catching keys or causing delays.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged