Y
Y
Yaroslav Ryazanov2016-09-25 20:04:34
C++ / C#
Yaroslav Ryazanov, 2016-09-25 20:04:34

How to read a specific line from a file?

Good afternoon. I'm trying to read a certain line from a file.

int set()
{
  setlocale(LC_ALL, "");
  int password;
  string name;
  
  // Создаём объект класса ofstream для записи и связываем его с файлом character_info.xml;
  ofstream character_info("character_info.xml");
  // Заполним его;
  character_info << "[Password] = " << password << ";" << endl;
  character_info << "[Username] = " << name << ";" << endl;
  
  // Откроем его только для чтения;
  character_info.open("character_infos.xml", ios_base::in);
  
  while (character_info.good())
  {
    // 13 так как первые 13 символов не учитываем;
    password = getline(13, character_info);
  }
  
  character_info.close();
  return password;
}

Tried like this. But the getline() function doesn't work. And, the assumption is that it will read subsequent characters as well. Those. "[Username] = "...
Tell me how can I enter a certain value from a file into a variable, focusing on its identifier. In this case, "[Username] = " ... ";" and "[Password] = "... ";".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AtomKrieg, 2016-09-25
@BRUC

1) a write-only file ofstream cannot be read from it. You can read from ifstream. Or read-write via fstream
www.cplusplus.com/reference/ostream/ostream
2) getline is used differently
www.cplusplus.com/reference/string/string/getline

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question