Go Back   Hardware Forums > Software Support Forums > Web Development

Reply
 
LinkBack Thread Tools
Old 28-05-2006, 03:46 PM   #1 (permalink) Top
Alpha Geek
 
Waffle's Avatar
 
Join Date: Apr 2004
Age: 20 Male
Posts: 2,270
Times Helpful: 51
My Mood: Angelic
Status: Offline

My Computer

Default C++ << std::end1;

Starting to learn C++, seems like a fairly good learning curve.

Anyway, ran in to an error when using code from a book:

PHP Code:
#include <iostream>

int main()
{
  
std::cout << "Hello world!\n"// new line
  
std::cout << "this is on a new line.." 
  
return 0;

that works fine

then i read about using std::end1; -

PHP Code:
#include <iostream>

int main()
{
  
std::cout << "Hello world!" << std::end1;
  
std::cout << "this is on a new line.." << std::end1;
  
std::cout << "and another";
  return 
0;

this returns an error message:

E2316 'end1' is not a member of 'std' in function main() at line xx


Suggestions why?

Send a message via MSN to Waffle   Reply With Quote
Whats this? Wireless Optical Black Desktop 1000
Wireless Optical Black Desktop 1000
Seller Price (inc. VAT) Delivery Total Price Availability Seller Rating
Misco.co.uk £26.99 £5.86 £32.85 In Stock Rated: 4 out of 5 - Number of votes: 1351
Micro Direct £29.36 £3.51 £32.87 In Stock Rated: 1 out of 5 - Number of votes: 38
euroffice £30.30 £4.64 £34.94 In Stock Rated: 4 out of 5 - Number of votes: 25
Old 28-05-2006, 05:49 PM   #2 (permalink) Top
The King

 
Addis's Avatar
 
Join Date: Jan 2004
Age: 18 Male
Posts: 5,254
Times Helpful: 402
My Mood: Drunk
Status: Offline

My Computer

Waffle, the endline function is spelt with an l at the end, not a 1.

So the statement would be:
Code:
cout << "testing testing" << endl;
cout << "New line this is";
cin.get(); //waits for user input
Also, you should try putting the statement
Code:
using namespace std;
above your int main() function, after the include headers so that you don't have to use the std:: bit before using the cout and cin objects.
__________________
Never trust a program you don't have the source code for.

My website | Powerful Desktop Linux | Linux for human beings | Linux for power users | Linux for ricers
Send a message via MSN to Addis   Reply With Quote
The Following User Says Thank You to Addis For This Useful Post: Show me >>
Old 28-05-2006, 06:18 PM   #3 (permalink) Top
Alpha Geek
 
Waffle's Avatar
 
Join Date: Apr 2004
Age: 20 Male
Posts: 2,270
Times Helpful: 51
My Mood: Angelic
Status: Offline

My Computer

An L? I'll be damned. Looked just like a one I didn't give it a second thought.

I'll give that statement a shot as well - thanks
Send a message via MSN to Waffle   Reply With Quote
Old 29-05-2006, 01:36 AM   #4 (permalink) Top
It's D Grav80 Of Luv
 
Karanislove's Avatar
 
Join Date: Jan 2006
Age: 23 Male
Posts: 3,460
Times Helpful: 160
My Mood: Cool
Status: Offline

My Computer

Quote:
Originally Posted by waffle
#include <iostream>

int main()
{
std::cout << "Hello world!" << std::end1;
std::cout << "this is on a new line.." << std::end1;
std::cout << "and another";
return 0;
}
In these types of functions, you can further reduce your lines... because you are not returning any value so instead of using...int main()...you can use void main() and your program will not look for a return value and you can remove that return 0 at the end.....
using "getch();" command will help in getting out of your program.....just use it in your function at the end.....
__________________
__________________________________________________ ___


Troubleshoot a Dead/Unbootable PC / Microsoft Events Viewer

Troubleshoot Printer / Most Common Home Audio Problems_
  Reply With Quote
Old 29-05-2006, 11:57 AM   #5 (permalink) Top
The King

 
Addis's Avatar
 
Join Date: Jan 2004
Age: 18 Male
Posts: 5,254
Times Helpful: 402
My Mood: Drunk
Status: Offline

My Computer

Karanislove, using
PHP Code:
void main() 
is not recommended. ANSI C++ states that main must return an integer. With C++ being a very fast compiled language, theres no need to do that. Many compilers like gcc will give you a warning for not returning a value. In java, using void main is also illegal.
__________________
Never trust a program you don't have the source code for.

My website | Powerful Desktop Linux | Linux for human beings | Linux for power users | Linux for ricers
Send a message via MSN to Addis   Reply With Quote
Old 29-05-2006, 09:31 PM   #6 (permalink) Top
It's D Grav80 Of Luv
 
Karanislove's Avatar
 
Join Date: Jan 2006
Age: 23 Male
Posts: 3,460
Times Helpful: 160
My Mood: Cool
Status: Offline

My Computer

I never had any problem with this function using Visual Studio 2003.net
__________________
__________________________________________________ ___


Troubleshoot a Dead/Unbootable PC / Microsoft Events Viewer

Troubleshoot Printer / Most Common Home Audio Problems_
  Reply With Quote
Old 29-05-2006, 11:35 PM   #7 (permalink) Top
The King

 
Addis's Avatar
 
Join Date: Jan 2004
Age: 18 Male
Posts: 5,254
Times Helpful: 402
My Mood: Drunk
Status: Offline

My Computer

Thats because the VC++ compiler allows it, but if you want to build portable applications, its better to use standard ANSI C++ code.
__________________
Never trust a program you don't have the source code for.

My website | Powerful Desktop Linux | Linux for human beings | Linux for power users | Linux for ricers
Send a message via MSN to Addis   Reply With Quote
Old 11-08-2006, 05:59 AM   #8 (permalink) Top
Banned
 
Join Date: Aug 2006
Posts: 153
Times Helpful: 20
My Mood: Amused
Status: Offline
I like void main() as well.

its endl instead of end1 because the L stands for line. Also you should include the library extension. For instance <iostream.h>

Why are you learning C++? It's dated. Move on to C#.
  Reply With Quote
Old 24-08-2006, 12:32 AM   #9 (permalink) Top
The King

 
Addis's Avatar
 
Join Date: Jan 2004
Age: 18 Male
Posts: 5,254
Times Helpful: 402
My Mood: Drunk
Status: Offline

My Computer

Quote:
Originally Posted by vol7ron View Post
I like void main() as well.

its endl instead of end1 because the L stands for line. Also you should include the library extension. For instance <iostream.h>
There's absolutely no point in using void main(), if you want to be a good developer, stick to standards when possible, especially something as trivial as that. VC might allow it, but gcc in Linux won't. And to prove it, here's the output of using iostream.h, with void main and no return statement on gcc4.
Code:
In file included from /usr/lib/gcc/i586-mandriva-linux-gnu/4.0.1/../../../../include/c++/4.0.1/backward/iostream.h:31,
                 from voidmain.c:1:
/usr/lib/gcc/i586-mandriva-linux-gnu/4.0.1/../../../../include/c++/4.0.1/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
voidmain.c:5: error: '::main' must return 'int'
The reason you don't put .h after the iostream is because iostream is for C++, not C. All C++ STL's have just the format #include <name>. To include C headers, you leave off the .h and prefix the header with "c". E.g. #include <cstdio>
Quote:
Why are you learning C++? It's dated. Move on to C#.
C++ is definitely not dead, it may be older than C# but it still has many many uses. KDE is primarily written in C++.

Why use the Unix security system when its dated and Windows is newer?
__________________
Never trust a program you don't have the source code for.

My website | Powerful Desktop Linux | Linux for human beings | Linux for power users | Linux for ricers

Last edited by Addis; 22-12-2006 at 10:05 PM.
Send a message via MSN to Addis   Reply With Quote
Old 25-08-2006, 06:52 AM   #10 (permalink) Top
Supreme Geek
 
Join Date: Jan 2003
Age: 27
Posts: 1,638
Times Helpful: 16
My Mood: Sick
Status: Offline

My Computer

You can also use \n inside your quotation marks (the "new line" character), it makes the code easier to read and faster to write.

\t for tabulations, as an FYI.

I understand c++ is much more powerful, but with Java you get the API for free, which is quite useful. After learning it a bit moving to c++ will be easier.
  Reply With Quote
Old 11-06-2008, 03:58 AM   #11 (permalink) Top
Geek Trainee
 
Join Date: Jun 2008
Posts: 1
Status: Offline
ha ha!I am very stupid for this small mistake.
thanks for sharing.
  Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 04:55 PM.


Copyright © 2000 - 2008 · HARDWAREFORUMS.COM · All rights reserved