私は ostringstreams と istringstreams に頭を悩ませようとしています。というわけで、いつものようにログインプログラムを作ってみました。しかし、ユーザー名とパスワードの変数の内容を計算しようとするたびに、アドレスが返されます!
プログラムの目的: 入力および出力文字列ストリームを使用してシミュレートされたログイン画面を作成する
コード:
#include<iostream>
#include<string>
#include<conio.h>
#include<stdio.h>
#include<sstream>
using namespace std;
int main(int argv, char *argc[]){
char ch;
ostringstream username,
password;
ostringstream *uptr,
*pptr;
uptr = &username;
pptr = &password;
cout << "Welcome" << endl << endl;
cout << "Enter a username: ";
do{
ch = _getch();
*uptr << ch;
cout << ch;
}while(ch != '\r');
cout << endl << "Enter a Password: ";
do{
ch = _getch();
*pptr << ch;
cout << "*";
}while(ch != '\r');
//if(username == "graywolfmedia25@gmail.com" && password == "deadbeefcoffee10031995"){
cout << endl << "username: " << *username << endl << "password: " << *password << endl;
//} else {
//cout << endl << "ACCESS DENIED" << endl;
//}
return 0;
}
最後に *uptr と *pptr を使用してみましたが、その前に、変数から直接書き込みと読み取りを試みました。