input _bstr_t
hi my program requires i use _bstr_t how would i input this because i cant use cin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
_bstr_t verification_code;
while (true)
{
cout << "Enter password: ";
getline(cin, enter_password);
if (enter_password == word_password)
{
cout << "Password is correct" << endl;
cout << "Enter Verification code: ";
cin >> verification_code;//error with >>
if (verification_code == x)
{
cout << "Verification is correct" << endl;
break;
}
else
{
cout << "Verification is incorrect" << endl;
continue;
}
}
else
{
cout << "Password is Incorrect" << endl;
continue;
}
}
return 0;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include <string>
#include <comutil.h>
#pragma comment(lib, "comsuppw" ) // link with comsuppw.lib
int main()
{
std::string str ;
std::getline( std::cin, str ) ;
// http://msdn.microsoft.com/en-us/library/9k3ebasf.aspx
_bstr_t bstr( str.c_str() ) ; // _bstr_t::_bstr_t( const char* ) ;
// http://msdn.microsoft.com/en-us/library/btdzb8eb.aspx
const char* cstr = bstr ; // _bstr_t::operator const char*( ) const ;
const std::string str2 = bstr ; // // _bstr_t::operator const char*( ) const ;
std::cout << str << '\n' << bstr << '\n' << cstr << '\n' << str2 << '\n' ;
std::wcout << bstr << L'\n' ; // _bstr_t::operator const wchar_t*( ) const ;
}
|
http://rextester.com/BBU46696
would str be the same as my verification_code variable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include <string>
#include <comutil.h>
#pragma comment(lib, "comsuppw" ) // link with comsuppw.lib
int main()
{
std::string verification_code ;
std::getline( std::cin, verification_code ) ;
// http://msdn.microsoft.com/en-us/library/9k3ebasf.aspx
_bstr_t bstr( str.c_verification_code() ) ; // _bstr_t::_bstr_t( const char* ) ;
// http://msdn.microsoft.com/en-us/library/btdzb8eb.aspx
const char* cstr = bstr ; // _bstr_t::operator const char*( ) const ;
const std::string str2 = bstr ; // // _bstr_t::operator const char*( ) const ;
std::cout << verification_code << '\n' << bstr << '\n' << cstr << '\n' << str2 << '\n' ;
std::wcout << bstr << L'\n' ; // _bstr_t::operator const wchar_t*( ) const ;
}
|
? would this be the right way to use it?
Last edited on
Yes.
1 2 3 4 5
|
std::string verification_code ;
std::getline( std::cin, verification_code ) ;
const _bstr_t bstr_verification_code( verification_code.c_str() ) ;
// use bstr_verification_code
|
Topic archived. No new replies allowed.