Game : Dialog Box Text & Read Line Per Line

closed account (zCpjy60M)
Hello I'm actually programming a game in c++ and SFML and I would like to know how to wright the text of dialog Box in my code (I'm french so I write original dialog in french and I need to change them easely .

&

I also need to know how to read line per line in a file open with iostream. In fact I have to say to my code "go pick that info at X line"

Thanks you in advance for your answer and sorry for my bad english
closed account (zCpjy60M)
Up 😊
Reading a file line by line is as easy as:
1
2
3
4
5
6
7
8
9
10
11
  ifstream src(__FILE__);
  if (!src)
  {
    perror(nullptr);
    return errno;
  }
  string line;
  while (getline(src, line))
  {
    // do sth. with line
  }


If you need to access lines by number it might by an option to store them in a vector.

Since I am not a SFML guy I can't help with the dialog box.
closed account (zCpjy60M)
Hello ,
Thanks for your answer but I still not understand . Can you not try to use vector in your example ? Thank you in advance :)
Here you go.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <vector>
#include <string>
#include <fstream>

using std::cout;
using std::cin;
using std::string;
using std::vector;
using std::ifstream;

int main()
{
    vector<string> lines; // create an empty vector of strings
    ifstream src(__FILE__);
    if (!src)
    {
        perror(nullptr);
        return errno;
    }
    string line;
    while (getline(src, line))
    {
        lines.push_back(line);
    }

    // just to see if we read all lines correctly

    for(const string& s : lines)
      cout << s << "\n";
}
closed account (zCpjy60M)
Ok thank you very much ;-)
Topic archived. No new replies allowed.