[SOLVED] [C++] std::ifstream does not want to read symbols
by doom_23 from LinuxQuestions.org on (#5E4K2)
Hello. I have a Quote:
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'?


file.txt |
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'?