If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

So what are you trying to achieve? The streams are overloaded already for char*, and if <string> is included, for std::string and std::wstring.

Regards,

Paul McKenzie

my objective is my function write() accept '+' for concat the literal strings\variables(directly in function). like these(without any function adicional):

Code:

Console a;
a.write("hello " + "world");

and

Code:

Console a;
string b="world";
a.write("hello " + b);

like you see, i don't use any function inside of my function
is my objective.
the error message that i recive:
"C:\Users\Joaquim\Documents\CodeBlocks\My Class\main.cpp|10|error: invalid operands of types 'const char [7]' and 'const char [6]' to binary 'operator+'|"
(you see the '7' and '6', i know that depends in char array size(the '\0' is ignored in size))

All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

Re: [RESOLVED] how can i convert write() procedure to cout?

then doesn't your original write template function work without overloading the function template for the case of const char * or char*?

All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

sorry about my english
(i understand that code works... but i mean anotherthing)
see these way that i want's:

Code:

a.write("hello " + "world")

like you see, i'm using the '+' operator for concat the char *. but the char * can't be concat directly that's why we must use casting or other functions for convert to string type. but can i change the parameter function for accept the '+' operator?

Re: [RESOLVED] how can i convert write() procedure to cout?

You don't need to change the paramater function. Using the original definitions for write, then

Code:

a.write((string("hello ") + "world");

should work as you are passing a type string which cout understands.

Note that if you are using 2 or more literal strings, then
"hello " + "world" can be written "hello ""world" which will be treated as "hello world" - but only for literal strings!

For your 'language', it might be easier for you to always 'convert' c-style char * strings to type string. ie

Code:

a.write((string("hello ") + string("world"));

Last edited by 2kaud; September 10th, 2013 at 04:27 PM.

All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

Re: [RESOLVED] how can i convert write() procedure to cout?

Why bother with concatenation at all with your write template function? why not just do

Code:

a.write("Hello ", "world");

All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/