ifstream如何知道定界符在哪里?
How does ifstream know where is the delimeter
所以当我读取file("animal。txt")时它显示的是
zebra
baboon
orangutan
gorilla
aardvark
lion
tiger
cougar
ocelot
panther
rat
mouse
gerbil
hamster
elephant
rhinoceros
hippopotamus
我想知道ist >> s
如何识别分隔符并将长字符串分隔成单独的单词。我在下面提供了一个文本和我的实现。
animal.txt
zebrababoonorangutangorillaaardvarkliontigercougarocelotpantherratmousegerbilhamsterelephantrhinoceroshippopotamus
和
SortedList readFile(string infile)
{
SortedList result;
string s;
ifstream ist(infile.c_str()); // open file
// Check if file opened correctly
if(ist.fail()) throw runtime_error("file not found");
// Read file into list
while(ist >> s){
cout<< s << endl;
cout << ist << endl;
result.insert(s);
}
return result;
}
operator>>
在左边应用于流,右边应用于字符串。
将从流中读取一个以"空格"分隔的单词到字符串中。
- 读取并忽略字符,直到
issapce()
为假。 - 读取并存储字符串字符,直到
isspace()
为真。
相关文章:
- C++我需要了解在哪里使用指针和双指针
- 未定义的引用在哪里
- 谷歌测试中的期望值存储在哪里
- 尽管遵循了规则,内存泄漏在哪里
- 静态数据成员模板专用化的实例化点在哪里
- 在哪里放置我的函数?进入我的母语 Gui 还是进入我的演示者?
- 在哪里声明结构运算符重载
- C++ 中的自定义异常:在哪里定义它们?
- 常量参数存储在哪里 (C++)?
- 如何在 c++ 中确定一条指令(以字节为单位)在哪里结束,另一条指令从哪里开始?
- 此递归函数的每次迭代的值存储在哪里?
- 如何告诉本机节点模块所需的dll存储在哪里?
- 在哪里存储跨平台C++应用存储?
- C++泛型类错误,问题出在哪里?
- 在标准中,模板参数的语法在哪里定义,例如,'std::function<int(char)>'?
- 将类作为主要参数的语法在哪里需要?
- 模板参数在 C++ 中存储在哪里?
- 我的重复检查代码中的错误究竟在哪里?
- 在哪里可以找到 std::bitset 的数据成员?
- ifstream如何知道定界符在哪里?