Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
laserlight
It depends. I have no clue what is the syntax and semantics of this programming language that you are trying to design and implement. What I do know is that whatever the syntax, you can translate a write to standard output in that language to C++ code involving std::cout, without having to write some C++ function (template, or class) with the C++ syntax that you have in mind. In other words, concentrating on C++ seems like it is taking you off course. Rather, concentrate on the syntax and semantics of your language, and how you will be translating that into C++ without unnecessary frills.
see these:
write("hello world" , NewLine, varname1)
to c++:
'write(' -> 'std::cout <<';
',' - > '<<';
'Newline' -> 'std::endl'
then i can delete the last ')' and add the ';'
(even for Read(varname1) is more or less the same.. except the Read() that must be '_getch()'. the 'cin' don't do the job, i think)
it's easy to translate;)
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
Cambalinho
(even for Read(varname1) is more or less the same.. except the Read() that must be '_getch()'. the 'cin' don't do the job, i think)
it's easy to translate;)
There is no standard C++ function that does this job. The _getch() function may or may not be supported by the compiler.
Maybe you should go over what are the standard functions of C++ before making assumptions about how to translate your functions to C++. So far, your version of "Read" is compiler specific.
If I use a compiler that doesn't have _getch(), or uses a different name than _getch(), then your translations will not work.
Regards,
Paul McKenzie
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
Paul McKenzie
There is no standard C++ function that does this job. The _getch() function may or may not be supported by the compiler.
Maybe you should go over what are the standard functions of C++ before making assumptions about how to translate your functions to C++. So far, your version of "Read" is compiler specific.
If I use a compiler that doesn't have _getch(), or uses a different name than _getch(), then your translations will not work.
Regards,
Paul McKenzie
unless i can do it with ReadConsole(), but i don't know how:(
Re: how can i convert write() procedure to cout?
i try these now:
ReadConsole(GetStdHandle(STD_OUTPUT_HANDLE),NULL,NULL,NULL,NULL);
but don't works:(
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
Cambalinho
i try these now:
ReadConsole(GetStdHandle(STD_OUTPUT_HANDLE),NULL,NULL,NULL,NULL);
but don't works:(
STD_OUTPUT_HANDLE for input??????:rolleyes:
See
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
2kaud
STD_OUTPUT_HANDLE for input??????:rolleyes:
i never notice that lol
now i get these error:
"First-chance exception at 0x76d0e1c8 in my classs.exe: 0xC0000005: Access violation writing location 0x00000000."
why?
(after press enter, if is another key, is just showed)
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
Cambalinho
i never notice that lol
now i get these error:
"First-chance exception at 0x76d0e1c8 in my classs.exe: 0xC0000005: Access violation writing location 0x00000000."
why?
(after press enter, if is another key, is just showed)
Because you haven't provided a buffer into which to read the characters! Read the documentation.
This will get 1 char from the input buffer
Code:
char ch;
DWORD read;
ReadConsole(GetStdHandle(STD_INPUT_HANDLE), &ch, 1, &read, NULL);
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
2kaud
Because you haven't provided a buffer into which to read the characters! Read the documentation.
This will get 1 char from the input buffer
Code:
char ch;
DWORD read;
ReadConsole(GetStdHandle(STD_INPUT_HANDLE), &ch, 1, &read, NULL);
thanks for all
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
Cambalinho
i try these now:
ReadConsole(GetStdHandle(STD_OUTPUT_HANDLE),NULL,NULL,NULL,NULL);
but don't works:(
That is a Windows API specific function, and this forum is geared towards standard C++, not Windows API functions. There is no "ReadConsole" function in standard C++.
If you're asking about Windows API functions, then there is a WinAPI forum to ask these questions.
Regards,
Paul McKenzie
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
Paul McKenzie
That is a Windows API specific function, and this forum is geared towards standard C++, not Windows API functions. There is no "ReadConsole" function in standard C++.
If you're asking about Windows API functions, then there is a WinAPI forum to ask these questions.
Regards,
Paul McKenzie
sorry about that, but the normal C++ don't have it. that's why you finished these topic with 1 API function. sorry about that
Re: how can i convert write() procedure to cout?
Code:
void write()
{
cout <<"";
}
template <typename A, typename ...B>
void write(A argHead, B... argTail)
{
cout << argHead;
write(argTail...);
}
template <typename A, typename ...B>
void write(char *argHead, B... argTail2)
{
string b=(string) argHead;
cout << b;
write(argTail2...);
}
is possible convert the char* type to string?
(my objective is accept the '+' for concat the strings)
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
Cambalinho
is possible convert the char* type to string?
When wil you have learned to use the documentation?
http://www.cplusplus.com/reference/s...string/string/
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
VictorN
ok.. i change these:
Code:
string b=(string) argHead;
to these:
Code:
string b=string( argHead);
but when i use it:
Code:
Console b;
b.write("hello " + "world" );
i get these error:
"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+'|"
what i need is that accept that line
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
Cambalinho
ok.. i change these:
Code:
string b=(string) argHead;
to these:
Code:
string b=string( argHead);
Why not just write
Code:
string b = argHead;
Quote:
Originally Posted by
Cambalinho
but when i use it:
Code:
Console b;
b.write("hello " + "world" );
i get these error:
"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+'|"
what i need is that accept that line[/QUOTE]This line has nothig to do with your previous question. Nor has it anything to do with the std::string class!
You are tryinf to add two pointers which is wrong. Is you want to concatenate thses strings - use strcat function.
Re: how can i convert write() procedure to cout?
Quote:
Originally Posted by
VictorN
Why not just write
Code:
string b = argHead;
what i need is that accept that line
This line has nothig to do with your previous question. Nor has it anything to do with the std::string class!
You are tryinf to add two pointers which is wrong. Is you want to concatenate thses strings - use strcat function.[/QUOTE]
let me ask 1 thing:
if i can do these:
Code:
b.write((string)"hello " + "world" );
why i can't do these:
Code:
template <typename A, typename ...B>
void write(char *argHead, B... argTail2)
{
cout <<(string) argHead;
write(argTail2...);
}
(the error stills be when i use these function)
?