1. cin>>a>>b;
2. 读取一整行:
string c;
getline(cin, c);
注意:如果在getline之前有用过cin>>a的操作,需使用cin.get()输出换行键,再继续操作。
例子:
// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
#include<string>
void back(string &path)
{
if (path == "C:\\>") {
cout<< path << endl;
return;
}
int i = path.rfind('\\');
if (i == 2) path = "C:\\>";
else path = path.substr(0, i) +">";
cout<< path << endl;
}
void addpath(string &path, string &order)
{
char c = '\\';
int n = order.length();
int m = path.length();
if (path[m-2] != '\\') path = path.substr(0, m-1) + "\\" + order.substr(3, n-3) + ">";
else {
path = path.substr(0, m-1) + order.substr(3, n-3) + ">";
}
cout<< path << endl;
}
int main()
{
// please define the C++ input here. For example: int a,b; cin>>a>>b;;
// please finish the function body here.
// please define the C++ output here. For example:cout<<____<<endl;
string path = "C:\\Users\\hp>";
cout << path <<endl;
int n;
cin >> n;
cin.get();
string order;
while(n--) {
getline(cin, order);
//cin.get();
//cout<<order<<endl;
if (order[3] == '.') back(path);
else addpath(path, order);
}
return 0;
}