Im just wondering, whats the difference between
std::cout
and cout
I've seen both in some sources, but I don't understand them. And what does :: do? : ) thanks
Im just wondering, whats the difference between
std::cout
and cout
I've seen both in some sources, but I don't understand them. And what does :: do? : ) thanks
:: is the scope resolution operator.
std::cout means to use the cout that resides in the std namespace
cout means to use the cout in whatever namespace you are in
ok then, keep in mind that im completely new to c++, i program vb but this is way different
whats a namespace ?
Instead of prefixing every function call with std::, you could put "using namespace std" after the includes. I think I read about a disadvantage to that somewhere, but I cant remember what.
The disadvantage is that nothing in the global namespace (or another imported namespace) can then have the same name as anything you have included in whatever namespaces that you have done away with by using the 'using' keyword.
Safer, is to say 'using std::cout;', 'using std::endl;', etc for only the identifiers you need. Safer still, is to stick with just using the namespace identifier for scope resolution when you use the identifiers.
thats how i see it:
imagine you develop a class library, and share it with your costumers etc, so they can use your library.
imagine you make a class that is part of your library called Cars, ie:
class Cars{
//code here
};
i install your library in my computer, but you'r not so lucky because other guy made another class that i have installed in my pc and he calle it Cars too, ok if pretend to use that class it will not do what i want because i both clases collide.
how can you prevent this? when u develop a set of classes is a good programming to put it
into namespaces ie
namespace terra
{
//here i put all my code and clases ie
class Cars{
//code here
};
}
ok know when u share your library your users to make use of the Cars class they must use
terra::Cars
or intead of typing everytime terra::something you define the namespace ie:
using namespace terra;
know you dont need to type terra::
then the user can start to create objects with that class with no problems
ie. Cars toyota;
if you r more lost after reading my post avoid it, because my english sucks
What they all said above.Im just wondering, whats the difference between
std::cout
and cout
I've seen both in some sources, but I don't understand them.
But wait, I also something to add! Some of the older compilers require you to include <iostream.h>, which is the nonstandard way of including it (i.e. the old way). If you include the .h version, then there is no std:: in front of cout, and you don't put 'using namespace std;' - because it's not declared/defined in a namespace in the old headers.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
This is also similar to my question about what \n does. What's the difference between no \n and \n. What does \n do?
\n is the newline character. As the name suggests it causes a newline to be outputted
>>What's the difference between no \n and \n. What does \n do?
>>>As the name suggests it causes a newline to be outputted
Generally true, except for in Windows applications, where it causes a funny square to be outputted unless you use a "\r\n" combo. Also, I think writing a '\n' to a file opened in text mode will actually output a "\r\n" unless you open the file in binary mode
P.S. You might want to get a good C++ book, or look over the tutorials on this site...
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Not if you open it in a linux enviroment.Also, I think writing a '\n' to a file opened in text mode will actually output a "\r\n" unless you open the file in binary mode
Oops, yeah. That's just a Windows thing, 'cause Microsoft said so
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Well, newline is just a character, and it's interpretation is application-specific (or so I imagine). If you so wished, you could make a text editor or console which treated £ as a newline character instead.