-
August 18th, 2013, 03:02 AM
#1
[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?
-
August 18th, 2013, 03:44 AM
#2
Re: what's wrong with 'cout' with strings?:(
Victor Nijegorodov
-
August 18th, 2013, 04:00 AM
#3
Re: what's wrong with 'cout' with strings?:(
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?
-
August 18th, 2013, 06:34 AM
#4
Re: what's wrong with 'cout' with strings?:(
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
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. 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/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 18th, 2013, 06:47 AM
#5
Re: what's wrong with 'cout' with strings?:(
Originally Posted by 2kaud
thanks for all
VictorN and 2kaud: do you recive the Rate?
(if not... sorry, it's a forum problem\rules)
-
August 18th, 2013, 06:54 AM
#6
Re: what's wrong with 'cout' with strings?:(
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.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. 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/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 18th, 2013, 07:15 AM
#7
Re: what's wrong with 'cout' with strings?:(
Originally Posted by 2kaud
Unfortunately no, I haven't received your Rate.
i'm realy sorry about that... it's by forum rules
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|