从.txt文件中读取一行,然后插入变量
Read one line from .txt file and insert into variable
我正在尝试编写一个程序,该程序将仅读取我的文本文件的第一行,然后将该数字输入到INT变量中。但是,我很困惑。
int highscore; // Starting highscore
ifstream myfile ("highscore.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline(myfile,highscore);
cout << highscore << endl;
}
myfile.close();
}
,但由于某种原因,即时通讯会遇到错误。|25|error: no matching function for call to 'getline(std::ifstream&, int&)'|
如果将getline替换为:
if (myfile >> highscore)
cout << "Read " << highscore << 'n';
else
cout << "Couldn't read an intn";
您将能够读取INT进入HighScore。您是否需要使用getline?
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- 从C++dll访问C#中的一行主要参数
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- boost::asio如何生成多个协同程序,然后加入它们
- 在C++中,我如何接受不同于同一行的用户输入
- 如何阅读两个单词,然后阅读C++中的一行?
- 需要从存档中读取一行文本.txt直到找到"hhh",然后转到下一行
- 如何声明一个数组,然后在另一行中赋值
- 我的程序在另一行中读取名字然后是姓氏,而我需要它一起读取名字和姓氏
- 从文件中读取直到一行的末尾,然后重复连续行的过程
- 从.txt文件中读取一行,然后插入变量
- 在C++中一次一行地从文本文件中读取int(好的字符,然后转换)时出现问题
- C++在文件中的一行中搜索某些单词,然后在这些单词后面插入一个单词
- c++如何将文本文件中的一行拆分为两行,然后将每行存储到两个不同的数组中
- 如何从.txt文件复制单词到数组.然后将每个单词打印在单独的一行上
- 在C++中读取一些整数,然后读取一行文本