[RESOLVED] what's wrong with 'cout' with strings?:(
see these class:
Code:
#include <iostream>
#include <Windows.h>
#define MY_BUFSIZE 1024
using namespace std;
class Console
{
char pszOldWindowTitle[MY_BUFSIZE];
public:
string Title() //the problem seems to be here, but no erro message here
{
GetWindowText(GetForegroundWindow(), pszOldWindowTitle, GetWindowTextLength(GetForegroundWindow()) + 1);
return string(pszOldWindowTitle);
}
void Title(string title) //these procedure works fine
{
SetConsoleTitle(title.c_str());
}
};
(sorry the indention, but i can't use 'TAB' key:()
and heres how i use it:
Code:
#include "stdafx.h"
#include "Console.h"
#include <iostream>
#include <conio.h>
int _tmain(int argc, _TCHAR* argv[])
{
Console a;
string b =string(a.Title());
cout << "Title: " << b << endl; //i get 1 problem in second '<<'
Sleep(5000);
a.Title("Hello World");
getch();
return 0;
}
error message:
1 - "error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)";
2 - " IntelliSense: no operator "<<" matches these operands".
what is wrong with cout???? isn't the 1st time that i get these type of error, but i continue without understand why:(
can anyone explain to me?
Re: what's wrong with 'cout' with strings?:(
Re: what's wrong with 'cout' with strings?:(
Quote:
Originally Posted by
VictorN
thank you. so every that i use the string, i must include that file.. thank you very much.
i have more 2 questions for close the topic:
1 - what means: title.c_str()?
(title it's a string variable)
2 - "warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch."
why these warning? the '_getch' can be used in Dev C++ too?
Re: what's wrong with 'cout' with strings?:(
Quote:
Originally Posted by
Cambalinho
thank you. so every that i use the string, i must include that file.. thank you very much.
i have more 2 questions for close the topic:
1 - what means: title.c_str()?
(title it's a string variable)
2 - "warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch."
why these warning? the '_getch' can be used in Dev C++ too?
1) See http://www.cplusplus.com/reference/string/string/c_str/
2) See http://stackoverflow.com/questions/8...-is-deprecated
Re: what's wrong with 'cout' with strings?:(
Quote:
Originally Posted by
2kaud
thanks for all
VictorN and 2kaud: do you recive the Rate?
(if not... sorry, it's a forum problem\rules:()
Re: what's wrong with 'cout' with strings?:(
Quote:
Originally Posted by
Cambalinho
thanks for all
VictorN and 2kaud: do you recive the Rate?
(if not... sorry, it's a forum problem\rules:()
Unfortunately no, I haven't received your Rate.:cry:
Re: what's wrong with 'cout' with strings?:(
Quote:
Originally Posted by
2kaud
Unfortunately no, I haven't received your Rate.:cry:
i'm realy sorry about that... it's by forum rules:(