完成所有string的操作

This commit is contained in:
邹晓航
2014-10-12 13:08:14 +08:00
parent bc6ff339d9
commit 4f0a4ed75e

View File

@@ -699,7 +699,7 @@ namespace TinySTL{
std::istream& operator >> (std::istream& is, string& str){
char ch;
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>
if (isblank(ch) || ch == '\n')
hasPrevBlank = true;
@@ -707,21 +707,29 @@ namespace TinySTL{
break;
}
is.putback(ch);
str.clear();
while (is.get(ch)){
if (ch != EOF && !isblank(ch) && ch != '\n'){
if (++index <= oldSize)
str[index - 1] = ch;
else
str.push_back(ch);
}else{//istream<61><6D>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
badState = true;
str.push_back(ch);
}else
break;
}
}
if (index < oldSize)
str.erase(str.begin() + index, str.end());
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 res(lhs);
return res += rhs;