在這個問題中我面臨一個問題: 「編寫一個C++控制檯程序來接受來自鍵盤的五個整數值,並用空格分隔。使用指針將這五個值存儲在一個數組中,然後在屏幕上打印數組的元素。「C++程序接受多個輸入並使用指針輸入數組
我試着做一個字符串變量,並接受來自用戶的5個整數,然後將其轉換爲整數,但它不能很好地工作,因爲它不會在空間之後採用數字。
任何幫助傢伙?
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main(){
string numbers;
getline(cin, numbers);
int arr[5];
int *ptr;
int values;
stringstream convert(numbers);
convert >> values;
cout << values;
}
我會親自用字符串流獲得的每一整數及使用類似'* PTR = thatInt;'納入指針。 – chris 2013-03-08 18:34:10