我試圖圍繞ostringstreams和istringstreams來包裝我的頭。所以,正如我一直所做的那樣,我做了一個登錄程序。但每次我嘗試關閉用戶名和密碼變量的內容時,它都會返回地址!爲什麼這會在控制檯中返回一個地址?
用途的程序:使用的輸入和輸出stringstreams
創建一個模擬的登錄屏幕代碼:
#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 == "[email protected]" && password == "deadbeefcoffee10031995"){
cout << endl << "username: " << *username << endl << "password: " << *password << endl;
//} else {
//cout << endl << "ACCESS DENIED" << endl;
//}
return 0;
}
我使用* uptr和* PPTR上次嘗試,但在此之前,我試圖只需從變量中直接寫入和讀取即可。
我不知道你在做什麼得到
std::string
,但儘量'username.str()' –@BryanChen你是一個美麗的人XD感謝您的幫助。並抱歉不清楚的代碼..我正在努力:P你能解釋.str()類嗎?或者將我連接到一個好的資源,將? –