How do i change std::cout
How do i change std::cout
#include <iostream>
#include <string>
using FText = std::string;
using Print = std::cout;
int main()
FText Submission1 = 0;
FText Submission2 = 0;
FText Operator = "";
return 0;
As you see I did,
using FText = std::string
how come i cant do a substitution for std::cout, The most confusing is the error i get
"No type named 'cout' in namespace 'std' "
can any pro coders help me im a begginer i dont like typing all if std::cout i managed to change string but cout is not working
im using xcode
cout
That sounds like a really bad idea.
– Danon
Aug 30 at 12:28
You can't write the code like this, for the same reason you can't write
int a; using TA = a;
– Algirdas Preidžius
Aug 30 at 12:33
int a; using TA = a;
"change string", "change cout" These terms do not fit what you are doing, or are at best ambiguous. Please try to use full sentences to describe your goals. Cheers!
– Lightness Races in Orbit
Aug 30 at 12:43
Being lazy for typing is one big (if not the most frequent) cause for unneccessarily obfuscated code. Writing
std::cout
is the most concice and readable way of writing std::cout
, consider that there are millions of c++ programmers and every one of them knows what std::cout
means, but only you know what Print
is– user463035818
Aug 30 at 12:50
std::cout
std::cout
std::cout
Print
3 Answers
3
You can use using
or typedef
to introduce a new name for a type.std::string
is a type, and these two are equivalent:
using
typedef
std::string
using FText = std::string;
typedef std::string FText;
But as the compiler says, std::cout
is not a type (it's a variable).
std::cout
You can introduce a new name for std::cout
using a reference:
std::cout
int main()
auto& Print = std::cout;
Print << "Hallo, Word!";
If you don't like look of namespace specifiers, you can do something like this:
int main()
using std::cout;
cout<< "Hallo, Word!";
You can create a new class say print class than override << insertion operator than use object of that class for printing.
class print
public:
int a;
void operator<<(print &obj)
cout<<obj.a<<endl;
;
print obj;
obj.a =1;
obj<<obj;
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
cout
is an instance, not a type.– πάντα ῥεῖ
Aug 30 at 12:27