C ++ stringstreams跳过一个字符 [英] C++ stringstreams skipping a character

查看:526
本文介绍了C ++ stringstreams跳过一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,第一行是> FileName.txt。我的目标是读取这一行,并将FileName.txt保存到名为name的变量。所以我有:

I have a file which the first line reads ">FileName.txt". My goal is to read this line, and save "FileName.txt" to a variable called name. So I have:

ifstream file;

/* File opening stuff */

string line, name;

getline(file,line);

stringstream converter(line);

converter >> name;

这会将> FileName.txt保存到变量 code>,但我需要删除'>'字符。我不知道如果我应该这样做之后,或者如果有一个方法可以跳过它完全使用 stringstream

This accomplishes saving ">FileName.txt" to the variable name, but I need to remove the '>' character. I am not sure if I should do that after this point, or if there is a way to skip over it entirely using the stringstream.

推荐答案

您可以很容易地跳过流:

You can skip over it with the stream fairly easily:

char ch;
converter >> ch; // skip initial >
converter >> name; // now read the name

这篇关于C ++ stringstreams跳过一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆