完成所有string的操作
This commit is contained in:
@@ -699,7 +699,7 @@ namespace TinySTL{
|
|||||||
std::istream& operator >> (std::istream& is, string& str){
|
std::istream& operator >> (std::istream& is, string& str){
|
||||||
char ch;
|
char ch;
|
||||||
string::size_type oldSize = str.size(), index = 0;
|
string::size_type oldSize = str.size(), index = 0;
|
||||||
bool hasPrevBlank = false, badState = false;
|
bool hasPrevBlank = false;
|
||||||
while (is.get(ch)){//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>հ<EFBFBD>
|
while (is.get(ch)){//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>հ<EFBFBD>
|
||||||
if (isblank(ch) || ch == '\n')
|
if (isblank(ch) || ch == '\n')
|
||||||
hasPrevBlank = true;
|
hasPrevBlank = true;
|
||||||
@@ -707,21 +707,29 @@ namespace TinySTL{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
is.putback(ch);
|
is.putback(ch);
|
||||||
|
str.clear();
|
||||||
while (is.get(ch)){
|
while (is.get(ch)){
|
||||||
if (ch != EOF && !isblank(ch) && ch != '\n'){
|
if (ch != EOF && !isblank(ch) && ch != '\n'){
|
||||||
if (++index <= oldSize)
|
str.push_back(ch);
|
||||||
str[index - 1] = ch;
|
}else
|
||||||
else
|
|
||||||
str.push_back(ch);
|
|
||||||
}else{//istream<61><6D>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
||||||
badState = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (index < oldSize)
|
|
||||||
str.erase(str.begin() + index, str.end());
|
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
std::istream& getline(std::istream& is, string& str, char delim){
|
||||||
|
char ch;
|
||||||
|
str.clear();
|
||||||
|
while (is.get(ch)){
|
||||||
|
if (ch == delim)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
str.push_back(ch);
|
||||||
|
}
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
std::istream& getline(std::istream& is, string& str){
|
||||||
|
return getline(is, str, '\n');
|
||||||
|
}
|
||||||
string operator+ (const string& lhs, const string& rhs){
|
string operator+ (const string& lhs, const string& rhs){
|
||||||
string res(lhs);
|
string res(lhs);
|
||||||
return res += rhs;
|
return res += rhs;
|
||||||
|
|||||||
Reference in New Issue
Block a user