using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace lab3._2 { struct Book { public string author; public string name; public string year; } class Program { static void Main(string[] args) { string path = "D:\\txt.txt"; string path1 = "D:\\txt1.txt"; FileStream fstr = File.OpenRead(path); Book[] Biblio = new Book[10]; StreamReader sr = File.OpenText(path); StreamWriter sw = new StreamWriter(path1,true); for (int i = 0; i<=Biblio.Length-1;i++) { string parts = sr.ReadLine(); string[] str = parts.Split(','); Biblio[i].author = str[0]; Biblio[i].name = str[1]; Biblio[i].year = str[2]; } for (int i = 0; i <= Biblio.Length - 1; i++) { Console.WriteLine(Biblio[i].name); } Console.WriteLine("avt: "); string vvd = Console.ReadLine(); for(int i = 0; i<=Biblio.Length-1; i++) { if (vvd == Biblio[i].author) { sw.WriteLine("Поиск по автору: { 0}\nПроизведение: { 1}\nДата обращения: { 2}\n", Biblio[i].author.ToString(), Biblio[i].name.ToString(), Biblio[i].year.ToString()); // Console.WriteLine("Поиск по автору: {0}\nПроизведение: {1}\nДата обращения: {2}\n",Biblio[i].author, Biblio[i].name, Biblio[i].year); } } sw.Close(); Console.ReadKey(); } } } - When writing to sw.WriteLine (...) it produces "The input line had the wrong format" - Comatose
- Below, under the tags (c # visual-studio) there is a "edit" menu. Add an example from a couple of lines of file contents from which to read. - Bulson
|
1 answer
Why not assume that the error message is correct?
The format string "Поиск по автору: { 0}\nПроизведение: { 1}\nДата обращения: { 2}\n" indeed erroneous. Spaces after the opening brace are not allowed.
And, based on the following commented out line, you had it right before.
- one"why not assume that the error message is correct" - "No! I can't catch it! I need to consult with my boss." - Igor
- @Igor: With Michal Ivanych? - VladD
- VladD Similarly, with him! - Igor
|