The "using namespace std;" and "std::"

Jan 13, 2014 at 3:01pm
I have just started learning C++ and wrote my first C++ Hello World program.
1
2
3
4
5
6
7
#include <iostream>
int main ()
{
using namespace std;
cout<< "Hello World"<<end1;
return 0;
}


I am using codeblocks and it shows the following errors:
1. In function 'int main()':" which is not an error but still why is it shown"
2. 'end1' was not declared in this scope.
Now I searched on web and people said that use "std::" instead of 'using namespace std' and replacing '\n"' with 'end1'. What is the problem with end1 and why most books like C++ Primer Plus 6 or Thinking in C++ have yet this code written in their books. I read the C++ Programming Language by Bjarne Stroustrup but the stuff was too professional that it can't be used as a reference and beginnning guide can you tell me any book that uses the present standard form of C++.
Jan 13, 2014 at 3:09pm
well, use endl (l as in line) instead of end1 (1 as in one)
Jan 13, 2014 at 3:11pm
It's a lower case 'L' not a number '1'. I hate the font on this site sometimes.

EDIT: On the off chance this was a troll by the way, it was a pretty good one. At least I got a laugh once I realized what was going on.
Last edited on Jan 13, 2014 at 3:12pm
Jan 13, 2014 at 3:25pm
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
int main ()
{

cout<< "Hello World"<<endl;
return 0;
}


using namespace std is written before int main() and is endl not end1
Jan 14, 2014 at 2:47pm
Some say that it's better to extract only names you need from the namespace (also with using directive)

1
2
3
4
5
6
7
8
9
10
#include <iostream>

using std::cout;
using std::endl;

int main()
{
          cout << "Hello world" << endl;
          return 0;
}
Jan 14, 2014 at 5:06pm
The worst and wrong book C++ Primer Plus taught me to write "using namespace" after int main() and I was cursing code::blocks and ISO for this.
Jan 14, 2014 at 5:08pm
It depends on what you mean by 'after int main()'. The following is fine:
1
2
3
4
5
6
7
#include <iostream>

int main()
{
    using namespace std;
    cout << "Whether or not it is after 'int main()' is open to interpretation" << endl;
}
Topic archived. No new replies allowed.