Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - gwyn0431

Pages: [1]
1
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;
}

2
General / Re: Event::TextEntered strange behavior..
« on: July 22, 2017, 07:17:58 pm »
Thanks a lot, man, a lack of knowledge here) I got it now.

3
General / Event::TextEntered strange behavior..
« on: July 22, 2017, 12:12:26 pm »
Hello everyone, i've just begun to learn SFML (couple days), my knowledge in c++ is average, i've read "C++ Primer", Lippman and already have some c++ code experience.
I have this simple code and my problem is, that it actually does't outputs characters to my console. It outputs everything i've typed AFTER i close the window. But, if i uncomment the << endl; statement, it outputs characters typed in real time. It seems i can't output my typed characters in real time, without having a new line after each character, which is super strange.
If anyone knows, please help)
P.S Sorry for my bad english sometimes, probably, i'm not a native speaker(

#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>

int main() {
    sf::RenderWindow window(sf::VideoMode(500, 500), "SFML works!");
    std::string display = "";
    window.setKeyRepeatEnabled(false);
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }

            else if (event.type == sf::Event::TextEntered) {
                std::cout << (char)(event.text.unicode) /* Try to uncomment THIS << std::endl */;
            }
        }

        window.display();

    }
    return 0;
}

Pages: [1]
anything