• Welcome to Valhalla Legends Archive.
 

I know this is just wrong but

Started by Mitosis, January 09, 2004, 05:44 AM

Previous topic - Next topic

Mitosis

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.

mejal

Quote from: Mitosis on January 09, 2004, 05:44 AM
 mystring = "hello there" endl;
Probably a misprint. Delete endl on this line.

Mitosis

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.

iago

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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Skywing

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.

iago

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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*