Article 5E4K2 [SOLVED] [C++] std::ifstream does not want to read symbols

[SOLVED] [C++] std::ifstream does not want to read symbols

by
doom_23
from LinuxQuestions.org on (#5E4K2)
Hello. I have a Quote:
file.txt
that have this syntaxis: first we have letter 'h', then there are 2 numbers, and then 5 letters:
Code:h 5 17 a b c d eI wrote a simple code that reads information from this file:
Code:#include <iostream>
#include <fstream>

int main(){
std::ifstream fin("file.txt");
if(!fin.is_open()){
return -1;
}

char buffer;
fin >> buffer; // 'h'
std::cout << buffer << " ";

int num;
while(fin >> num){
std::cout << num << " ";
}

for(int i = 0; i < 5; i++){
fin >> buffer;
std::cout << buffer << " ";
}
std::cout << "\n";
return 0;
}However, this is an output i get:
Code:h 5 17 h h h h hWhy there are no letters 'a', 'b', 'c', 'd' and 'e'?latest?d=yIl2AUoC8zA latest?i=Gwlynwo-PHY:3xEJhG3i0qg:F7zBnMy latest?i=Gwlynwo-PHY:3xEJhG3i0qg:V_sGLiP latest?d=qj6IDK7rITs latest?i=Gwlynwo-PHY:3xEJhG3i0qg:gIN9vFwGwlynwo-PHY
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments