Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: Mitosis on January 09, 2004, 05:44 AM

Title: I know this is just wrong but
Post by: Mitosis on January 09, 2004, 05:44 AM
Ok I copied exactly out of my book but I  keep getting compiler errors.This is what I got.

#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
 
 string mystring;
 mystring = "hello there" endl;
 cout << mystring << endl;
 system("PAUSE");   
 return 0;
}

It keeps saying mystring = "hello there" endl; is wrong. But its exactly out of the book. Any help would be aprecaited.
Title: Re:I know this is just wrong but
Post by: mejal on January 09, 2004, 06:12 AM
Quote from: Mitosis on January 09, 2004, 05:44 AM
 mystring = "hello there" endl;
Probably a misprint. Delete endl on this line.
Title: Re:I know this is just wrong but
Post by: Mitosis on January 09, 2004, 06:43 AM
Thanks Mejal. It worked. Weird though, in my book C++ for dummies it always tells me to have endl at the end just before the ;. Ohwell thanks for your help.
Title: Re:I know this is just wrong but
Post by: iago on January 09, 2004, 06:59 AM
To put more than one parameter on a cout line, they have to be seperated by <<'s.  So on that line, put << between "hello there" and end.
Title: Re:I know this is just wrong but
Post by: Skywing on January 09, 2004, 12:00 PM
Quote from: Mitosis on January 09, 2004, 06:43 AM
Thanks Mejal. It worked. Weird though, in my book C++ for dummies it always tells me to have endl at the end just before the ;. Ohwell thanks for your help.
endl is only used in conjunction with cout, cerr, or other ostream objects.
Title: Re:I know this is just wrong but
Post by: iago on January 09, 2004, 01:04 PM
Actually, Skywing's right, I didn't really need that code.  You only want to have endl on lines with cout and similar operators, not in string or anything like that.