我正试图围绕 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,但在此之前我尝试直接从变量中写入和读取。