1
General / getline skips the first line of txt file, if i use myFile >> str before it. Why?
« on: July 24, 2017, 02:33:55 pm »
Hello everyone. Does anyone knows, why getline() skips the first line of txt file, if i use myFile >> str before it? I mean if i output some amount string of file before using getline, then it will skip that amount of lines and would output only those one, that are left.
Does someone know why?
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main() {
std::string output;
std::ifstream openfile("map1.txt");
if (openfile.is_open()) {
std::string tileLocation;
openfile >> tileLocation;
while (!openfile.eof()) {
std::string str;
std::getline(openfile, str);
cout << "string: " << str << endl;
}
}
return 0;
}
Does someone know why?
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main() {
std::string output;
std::ifstream openfile("map1.txt");
if (openfile.is_open()) {
std::string tileLocation;
openfile >> tileLocation;
while (!openfile.eof()) {
std::string str;
std::getline(openfile, str);
cout << "string: " << str << endl;
}
}
return 0;
}