readfile https://www.e-learn.cn/tag/readfile zh-hans How do you read n bytes from a file and put them into a vector<uint8_t> using iterators? https://www.e-learn.cn/topic/4118428 <span>How do you read n bytes from a file and put them into a vector&lt;uint8_t&gt; using iterators?</span> <span><span lang="" about="/user/214" typeof="schema:Person" property="schema:name" datatype="">半腔热情</span></span> <span>2021-02-19 15:30:23</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Based on this this question:</p> <p>How to read a binary file into a vector of unsigned chars</p> <p>In the answer they have:</p> <pre><code>std::vector&lt;BYTE&gt; readFile(const char* filename) { // open the file: std::basic_ifstream&lt;BYTE&gt; file(filename, std::ios::binary); // read the data: return std::vector&lt;BYTE&gt;((std::istreambuf_iterator&lt;BYTE&gt;(file)), std::istreambuf_iterator&lt;BYTE&gt;()); } </code></pre> <p>Which reads the entire file into the vector.</p> <p>What I want to do is read (for example) 100 bytes at a time in the vector, then do stuff, and then read the next 100 bytes into the vector (clear the vector between). I don't see how to specify how much of the file to read (i.e. how to setup the iterators). Is that even possible?</p> <p>I am trying to avoid having to write my own code loop to copy each byte at a time.</p> <br /><h3>回答1:</h3><br /><p>You can use <code>ifstream::read</code> for that.</p> <pre><code>std::vector&lt;BYTE&gt; v(100); while ( file.read(reinterpret_cast&lt;char*&gt;(v.data()), 100) ) { // Find out how many characters were actually read. auto count = file.gcount(); // Use v up to count BTYEs. } </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>You could write a function to:</p> <pre><code>void readFile( const std::string &amp;fileName, size_t chunk, std::function&lt;void(const std::vector&lt;BYTE&gt;&amp;)&gt; proc ) { std::ifstream f( fileName ); std::vector&lt;BYTE&gt; v(chunk); while( f.read( v.data(), v.size() ) ) { v.resize( f.gcount() ); proc( v ); v.resize( chunk ); } } </code></pre> <p>then usage is simple:</p> <pre><code>void process( const std::vector&lt;BYTE&gt; &amp;v ) { ... } readFile( "foobar", 100, process ); // call process for every 100 bytes of data </code></pre> <p>or you can use lambda etc for callback.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>Or you can write your own function for that:</p> <pre><code>template&lt;typename Data&gt; std::istreambuf_iterator&lt;Data&gt; readChunk(std::istreambuf_iterator&lt;Data&gt;&amp; curr, std::vector&lt;Data&gt;&amp; vec, size_t chunk = 100) { for (int i = 0; curr != std::istreambuf_iterator&lt;Data&gt;() &amp;&amp; i &lt; chunk; ++i, ++curr) { vec.emplace_back(*curr); } return curr; } </code></pre> <p>and use it as:</p> <pre><code>std::ifstream file("test.cpp"); std::vector&lt;BYTE&gt; v; std::istreambuf_iterator&lt;BYTE&gt; curr(file); readChunk&lt;BYTE&gt;(curr, v); </code></pre> <p>And you can call this function again.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/50491833/how-do-you-read-n-bytes-from-a-file-and-put-them-into-a-vectoruint8-t-using-it</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c-0" hreflang="zh-hans">c++</a></div> <div class="field--item"><a href="/tag/vector" hreflang="zh-hans">vector</a></div> <div class="field--item"><a href="/tag/readfile" hreflang="zh-hans">readfile</a></div> <div class="field--item"><a href="/tag/ifstream" hreflang="zh-hans">ifstream</a></div> </div> </div> Fri, 19 Feb 2021 07:30:23 +0000 半腔热情 4118428 at https://www.e-learn.cn How do you read n bytes from a file and put them into a vector<uint8_t> using iterators? https://www.e-learn.cn/topic/4118423 <span>How do you read n bytes from a file and put them into a vector&lt;uint8_t&gt; using iterators?</span> <span><span lang="" about="/user/234" typeof="schema:Person" property="schema:name" datatype="">喜你入骨</span></span> <span>2021-02-19 15:25:07</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Based on this this question:</p> <p>How to read a binary file into a vector of unsigned chars</p> <p>In the answer they have:</p> <pre><code>std::vector&lt;BYTE&gt; readFile(const char* filename) { // open the file: std::basic_ifstream&lt;BYTE&gt; file(filename, std::ios::binary); // read the data: return std::vector&lt;BYTE&gt;((std::istreambuf_iterator&lt;BYTE&gt;(file)), std::istreambuf_iterator&lt;BYTE&gt;()); } </code></pre> <p>Which reads the entire file into the vector.</p> <p>What I want to do is read (for example) 100 bytes at a time in the vector, then do stuff, and then read the next 100 bytes into the vector (clear the vector between). I don't see how to specify how much of the file to read (i.e. how to setup the iterators). Is that even possible?</p> <p>I am trying to avoid having to write my own code loop to copy each byte at a time.</p> <br /><h3>回答1:</h3><br /><p>You can use <code>ifstream::read</code> for that.</p> <pre><code>std::vector&lt;BYTE&gt; v(100); while ( file.read(reinterpret_cast&lt;char*&gt;(v.data()), 100) ) { // Find out how many characters were actually read. auto count = file.gcount(); // Use v up to count BTYEs. } </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>You could write a function to:</p> <pre><code>void readFile( const std::string &amp;fileName, size_t chunk, std::function&lt;void(const std::vector&lt;BYTE&gt;&amp;)&gt; proc ) { std::ifstream f( fileName ); std::vector&lt;BYTE&gt; v(chunk); while( f.read( v.data(), v.size() ) ) { v.resize( f.gcount() ); proc( v ); v.resize( chunk ); } } </code></pre> <p>then usage is simple:</p> <pre><code>void process( const std::vector&lt;BYTE&gt; &amp;v ) { ... } readFile( "foobar", 100, process ); // call process for every 100 bytes of data </code></pre> <p>or you can use lambda etc for callback.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>Or you can write your own function for that:</p> <pre><code>template&lt;typename Data&gt; std::istreambuf_iterator&lt;Data&gt; readChunk(std::istreambuf_iterator&lt;Data&gt;&amp; curr, std::vector&lt;Data&gt;&amp; vec, size_t chunk = 100) { for (int i = 0; curr != std::istreambuf_iterator&lt;Data&gt;() &amp;&amp; i &lt; chunk; ++i, ++curr) { vec.emplace_back(*curr); } return curr; } </code></pre> <p>and use it as:</p> <pre><code>std::ifstream file("test.cpp"); std::vector&lt;BYTE&gt; v; std::istreambuf_iterator&lt;BYTE&gt; curr(file); readChunk&lt;BYTE&gt;(curr, v); </code></pre> <p>And you can call this function again.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/50491833/how-do-you-read-n-bytes-from-a-file-and-put-them-into-a-vectoruint8-t-using-it</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c-0" hreflang="zh-hans">c++</a></div> <div class="field--item"><a href="/tag/vector" hreflang="zh-hans">vector</a></div> <div class="field--item"><a href="/tag/readfile" hreflang="zh-hans">readfile</a></div> <div class="field--item"><a href="/tag/ifstream" hreflang="zh-hans">ifstream</a></div> </div> </div> Fri, 19 Feb 2021 07:25:07 +0000 喜你入骨 4118423 at https://www.e-learn.cn How do you read n bytes from a file and put them into a vector<uint8_t> using iterators? https://www.e-learn.cn/topic/4118422 <span>How do you read n bytes from a file and put them into a vector&lt;uint8_t&gt; using iterators?</span> <span><span lang="" about="/user/208" typeof="schema:Person" property="schema:name" datatype="">百般思念</span></span> <span>2021-02-19 15:24:39</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Based on this this question:</p> <p>How to read a binary file into a vector of unsigned chars</p> <p>In the answer they have:</p> <pre><code>std::vector&lt;BYTE&gt; readFile(const char* filename) { // open the file: std::basic_ifstream&lt;BYTE&gt; file(filename, std::ios::binary); // read the data: return std::vector&lt;BYTE&gt;((std::istreambuf_iterator&lt;BYTE&gt;(file)), std::istreambuf_iterator&lt;BYTE&gt;()); } </code></pre> <p>Which reads the entire file into the vector.</p> <p>What I want to do is read (for example) 100 bytes at a time in the vector, then do stuff, and then read the next 100 bytes into the vector (clear the vector between). I don't see how to specify how much of the file to read (i.e. how to setup the iterators). Is that even possible?</p> <p>I am trying to avoid having to write my own code loop to copy each byte at a time.</p> <br /><h3>回答1:</h3><br /><p>You can use <code>ifstream::read</code> for that.</p> <pre><code>std::vector&lt;BYTE&gt; v(100); while ( file.read(reinterpret_cast&lt;char*&gt;(v.data()), 100) ) { // Find out how many characters were actually read. auto count = file.gcount(); // Use v up to count BTYEs. } </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>You could write a function to:</p> <pre><code>void readFile( const std::string &amp;fileName, size_t chunk, std::function&lt;void(const std::vector&lt;BYTE&gt;&amp;)&gt; proc ) { std::ifstream f( fileName ); std::vector&lt;BYTE&gt; v(chunk); while( f.read( v.data(), v.size() ) ) { v.resize( f.gcount() ); proc( v ); v.resize( chunk ); } } </code></pre> <p>then usage is simple:</p> <pre><code>void process( const std::vector&lt;BYTE&gt; &amp;v ) { ... } readFile( "foobar", 100, process ); // call process for every 100 bytes of data </code></pre> <p>or you can use lambda etc for callback.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>Or you can write your own function for that:</p> <pre><code>template&lt;typename Data&gt; std::istreambuf_iterator&lt;Data&gt; readChunk(std::istreambuf_iterator&lt;Data&gt;&amp; curr, std::vector&lt;Data&gt;&amp; vec, size_t chunk = 100) { for (int i = 0; curr != std::istreambuf_iterator&lt;Data&gt;() &amp;&amp; i &lt; chunk; ++i, ++curr) { vec.emplace_back(*curr); } return curr; } </code></pre> <p>and use it as:</p> <pre><code>std::ifstream file("test.cpp"); std::vector&lt;BYTE&gt; v; std::istreambuf_iterator&lt;BYTE&gt; curr(file); readChunk&lt;BYTE&gt;(curr, v); </code></pre> <p>And you can call this function again.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/50491833/how-do-you-read-n-bytes-from-a-file-and-put-them-into-a-vectoruint8-t-using-it</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c-0" hreflang="zh-hans">c++</a></div> <div class="field--item"><a href="/tag/vector" hreflang="zh-hans">vector</a></div> <div class="field--item"><a href="/tag/readfile" hreflang="zh-hans">readfile</a></div> <div class="field--item"><a href="/tag/ifstream" hreflang="zh-hans">ifstream</a></div> </div> </div> Fri, 19 Feb 2021 07:24:39 +0000 百般思念 4118422 at https://www.e-learn.cn Fortran read mixed text and numbers https://www.e-learn.cn/topic/4115941 <span>Fortran read mixed text and numbers</span> <span><span lang="" about="/user/118" typeof="schema:Person" property="schema:name" datatype="">不打扰是莪最后的温柔</span></span> <span>2021-02-19 03:44:04</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am using Fortran 90 to read a file that contains data in the following format</p> <pre><code>number# 125 var1= 2 var2= 1 var3: 4 . . . . number# 234 var1= 3 var2= 5 var3: 1 </code></pre> <p>I tried the following command and works fine</p> <pre><code>read (2,*) tempstr , my_param(1), tempstr , my_param(2), tempstr , my_param(3) </code></pre> <p>Problem is when the numbers become larger and there is no space between string and number, i.e. the data looks as following:</p> <pre><code>number# 125 var1= 2 var2=124 var3: 4 </code></pre> <p>I tried</p> <pre><code> read (2,512) my_param(1), my_param(2), my_param(3) 512 format('number#', i, 'var1=', i, 'var2=', i, 'var3:', i) </code></pre> <p>It reads all number as zero</p> <p>I can't switch to some other language. The data set is huge, so I can't pre-process it. Also, the delimiters are not the same every time. Can someone please help with the problem?</p> <p>Thanks in advance</p> <br /><h3>回答1:</h3><br /><p>While I still stand with my original answer, particularly because the input data is already so close to what a namelist file would look like, let's assume that you really can't make any preprocessing of the data beforehand.</p> <p>The next best thing is to read in the whole line into a <code>character(len=&lt;enough&gt;)</code> variable, then extract the values out of that with String Manipulation. Something like this:</p> <pre><code>program mixed2 implicit none integer :: num, val1, val2, val3 character(len=50) :: line integer :: io_stat open(unit=100, file='data.dat', action='READ', status='OLD') do read(100, '(A)', iostat=io_stat) line if (io_stat /= 0) exit call get_values(line, num, val1, val2, val3) print *, num, val1, val2, val3 end do close(100) contains subroutine get_values(line, n, v1, v2, v3) implicit none character(len=*), intent(in) :: line integer, intent(out) :: n, v1, v2, v3 integer :: idx ! Search for "number#" idx = index(line, 'number#') + len('number#') ! Get the integer after that word read(line(idx:idx+3), '(I4)') n idx = index(line, 'var1') + len('var1=') read(line(idx:idx+3), '(I4)') v1 idx = index(line, 'var2') + len('var3=') read(line(idx:idx+3), '(I4)') v2 idx = index(line, 'var3') + len('var3:') read(line(idx:idx+3), '(I4)') v3 end subroutine get_values end program mixed2 </code></pre> <p>Please note that I have not included any error/sanity checking. I'll leave that up to you.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>First up, 720 thousand lines is not too much for pre-processing. Tools like <code>sed</code> and <code>awk</code> work mostly on a line-by-line basis, so they scale really well.</p> <p>What I have actually done was to convert the data in such a way that I could use namelists:</p> <pre class="lang-sh prettyprint-override"><code>$ cat preprocess.sed # Add commas between values # Space followed by letter -&gt; insert comma s/ \([[:alpha:]]\)/ , \1/g # "number" is a key word in Fortran, so replace it with num s/number/num/g # Replace all possible data delimitors with the equals character s/[#:]/=/g # add the '&amp;mydata' namelist descriptor to the beginning s/^/\&amp;mydata /1 # add the namelist closing "/" character to the end of the line: s,$,/,1 $ sed -f preprocess.sed &lt; data.dat &gt; data.nml </code></pre> <p>Check that the data was correctly preprocessed:</p> <pre><code>$ tail -3 data.dat number#1997 var1=114 var2=130 var3:127 number#1998 var1=164 var2=192 var3: 86 number#1999 var1=101 var2= 48 var3:120 $ tail -3 data.nml &amp;mydata num=1997 , var1=114 , var2=130 , var3=127/ &amp;mydata num=1998 , var1=164 , var2=192 , var3= 86/ &amp;mydata num=1999 , var1=101 , var2= 48 , var3=120/ </code></pre> <p>Then you can read it with this fortran program:</p> <pre><code>program read_mixed implicit none integer :: num, var1, var2, var3 integer :: io_stat namelist /mydata/ num, var1, var2, var3 open(unit=100, file='data.nml', status='old', action='read') do read(100, nml=mydata, iostat=io_stat) if (io_stat /= 0) exit print *, num, var1, var2, var3 end do close(100) end program read_mixed </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/38133083/fortran-read-mixed-text-and-numbers</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/fortran" hreflang="zh-hans">fortran</a></div> <div class="field--item"><a href="/tag/readfile" hreflang="zh-hans">readfile</a></div> <div class="field--item"><a href="/tag/fortran90" hreflang="zh-hans">fortran90</a></div> </div> </div> Thu, 18 Feb 2021 19:44:04 +0000 不打扰是莪最后的温柔 4115941 at https://www.e-learn.cn How to read file in Java Script line by line from hardcoded path and name of the file? https://www.e-learn.cn/topic/4079784 <span>How to read file in Java Script line by line from hardcoded path and name of the file?</span> <span><span lang="" about="/user/63" typeof="schema:Person" property="schema:name" datatype="">女生的网名这么多〃</span></span> <span>2021-02-08 12:09:42</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I would like to read file in Java Script. The best it would be to read line by line, but there is also possibility to read the whole file at once. Generally on the web there is quite a lot of implementations, but I would like to read a file in very simple way by entering, hardcoded path and file name in the Java Script code, not but any buttons or something like this. The pseudo code below:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; var file = FileReader("home/test.txt");//hardcoded path and name of the file var listOfLines = []; var line = file.readLine(); while(line != eof) { listOfLines.push(file.readLine()); file.readLine(); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Is there such possibility to do something like this. Thank you.</p> <br /><h3>回答1:</h3><br /><p>That would be a pretty big security hole, if your browser could simply read arbityry files from your filesystem. Think, every banner on the web could read configuation files of your OS, and stuff like that.</p> <p>also check this question/answer: How to set a value to a file input in HTML?<br /> slightly different question, same problem.</p> <p>But if the client <em>gives</em> your app the file you should process, that's something different.</p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>//use fetch() to get the file content function fetchFile(file){ const {name, lastModified, size, type} = file; return fetch(URL.createObjectURL(file)) .then(response =&gt; response.text()) .then(text =&gt; ({name, lastModified, size, type, text})); } //use a FileReader to get the content function readFile(file){ const {name, lastModified, size, type} = file; return new Promise((resolve, reject) =&gt; { const reader = new FileReader(); reader.onload = () =&gt; resolve(reader.result); reader.onerror = reject; reader.readAsText(file); }) .then(text =&gt; ({name, lastModified, size, type, text})); } let input = document.querySelector('input'); input.onchange = function(){ const promises = [...input.files].map(fetchFile); //fetch //const promises = [...input.files].map(readFile); //FileReader Promise.all(promises) .then(files =&gt; { console.log(files); }) }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="file" /&gt;</code></pre> </div> </div> <p>This is just a quick snippet. You'd have to check wether there are further security measures/obstacles due to the fact that a web page is accessing local files; but since this snippet is working, I'm confident that you're good.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>FileReader is working well and it is well supported, see:</p> <p>https://caniuse.com/#search=FileReader</p> <p>even IE has a partial support.</p> <p>But it can read <strong>ONLY</strong> file returned from the user. You cannot read any file with an hardcoded path from the developer. Of course that is for security reasons, the javascript engine in the browser runs in a sandbox.</p> <p>PS Also, to read big csv files from javascript, I suggest this library, that I used many times with success:</p> <p>https://www.papaparse.com/</p> <p>reference:</p> <p>https://www.w3.org/TR/FileAPI/</p> <p>https://www.w3.org/TR/FileAPI/#dfn-filereader</p> <p>https://developer.mozilla.org/it/docs/Web/API/FileReader</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/48994679/how-to-read-file-in-java-script-line-by-line-from-hardcoded-path-and-name-of-the</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/javascript" hreflang="zh-hans">javascript</a></div> <div class="field--item"><a href="/tag/html" hreflang="zh-hans">html</a></div> <div class="field--item"><a href="/tag/file" hreflang="zh-hans">file</a></div> <div class="field--item"><a href="/tag/readfile" hreflang="zh-hans">readfile</a></div> <div class="field--item"><a href="/tag/eof" hreflang="zh-hans">eof</a></div> </div> </div> Mon, 08 Feb 2021 04:09:42 +0000 女生的网名这么多〃 4079784 at https://www.e-learn.cn Implementing a ReadFile with a timeout inducing too much CPU ussage https://www.e-learn.cn/topic/4039028 <span>Implementing a ReadFile with a timeout inducing too much CPU ussage</span> <span><span lang="" about="/user/119" typeof="schema:Person" property="schema:name" datatype="">一个人想着一个人</span></span> <span>2021-01-29 11:21:15</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I use kernel32.dll ReadFile to read the HID output of a connected device. I wanted to create a timeout because this call is a blocking method and if it hangs for any reason the main loop in my application also hangs.</p> <pre><code> [DllImport("kernel32.dll", SetLastError = true)] static internal extern bool ReadFile(IntPtr hFile, [Out] byte[] lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, IntPtr lpOverlapped); public static HidLibrary.HidDeviceData.ReadStatus FastReadWithTimeout(this HidLibrary.HidDevice device, byte[] inputBuffer, int timeout) { return FastReadWithTimeoutWorker(device, inputBuffer, timeout).GetAwaiter().GetResult(); } private static async Task&lt;HidLibrary.HidDeviceData.ReadStatus&gt; FastReadWithTimeoutWorker(HidLibrary.HidDevice device, byte[] inputBuffer, int timeout) { var task = Task.Run(async () =&gt; { try { uint bytesRead; if (NativeMethods.ReadFile(device.Handle, inputBuffer, (uint)inputBuffer.Length, out bytesRead, IntPtr.Zero)) { return HidLibrary.HidDeviceData.ReadStatus.Success; } else { return HidLibrary.HidDeviceData.ReadStatus.NoDataRead; } } catch (Exception) { return HidLibrary.HidDeviceData.ReadStatus.ReadError; } }); if (await Task.WhenAny(task, Task.Delay(timeout)) == task) { return task.Result; } else { device.CancelIO(); return HidLibrary.HidDeviceData.ReadStatus.WaitTimedOut; } } </code></pre> <p>The issue is my current method of doing this causing more CPU overhead than I can allow. Is there something wrong with the way I am doing this or is there a better way to implement a timeout in a native method?</p> <p>I also just discovered SetCommTimeouts(), but am having trouble finding a working example of it, documentation is spotty.</p> <p>来源:<code>https://stackoverflow.com/questions/53362883/implementing-a-readfile-with-a-timeout-inducing-too-much-cpu-ussage</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c" hreflang="zh-hans">c#</a></div> <div class="field--item"><a href="/tag/readfile" hreflang="zh-hans">readfile</a></div> </div> </div> Fri, 29 Jan 2021 03:21:15 +0000 一个人想着一个人 4039028 at https://www.e-learn.cn Python read .txt File -> list https://www.e-learn.cn/topic/4028752 <span>Python read .txt File -&gt; list</span> <span><span lang="" about="/user/36" typeof="schema:Person" property="schema:name" datatype="">ぃ、小莉子</span></span> <span>2021-01-28 14:38:03</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have a .txt File and I want to get the values in a list. The format of the txt file should be:</p> <pre><code>value0,timestamp0 value1,timestamp1 ... ... ... </code></pre> <p>In the end I want to get a list with </p> <pre><code>[[value0,timestamp0],[value1,timestamp1],.....] </code></pre> <p>I know it's easy to get these values by</p> <pre><code>direction = [] for line in open(filename): direction,t = line.strip().split(',') direction = float(direction) t = long(t) direction.append([direction,t]) return direction </code></pre> <p>But I have a big problem: When creating the data I forgot to insert a "\n" in each row.</p> <p>Thats why I have this format:</p> <pre><code>value0, timestamp0value1,timestamp1value2,timestamp2value3..... </code></pre> <p>Every timestamp has exactly 13 characters.</p> <p>Is there a way to get these data in a list as I want it? Would be very much work get the data again.</p> <p>Thanks Max</p> <br /><h3>回答1:</h3><br /><p>I coded a quickie using your example, and not using 13 but len("timestamp") so you can adapt</p> <pre><code>instr = "value,timestampvalue2,timestampvalue3,timestampvalue4,timestamp" previous_i = 0 for i,c in enumerate(instr): if c==",": next_i = i+len("timestamp")+1 print(instr[previous_i:next_i]) previous_i = next_i </code></pre> <p>output is descrambled:</p> <pre><code>value,timestamp value2,timestamp value3,timestamp value4,timestamp </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><pre><code>import re input = "value0,0123456789012value1,0123456789012value2,0123456789012value3" for (line, value, timestamp) in re.findall("(([^,]+),(.{13}))", input): print value, timestamp </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>You will have to strip the last , but you can insert a comma after every 13 chars following a comma:</p> <pre><code>import re s = "-0.1351197,1466615025472-0.25672746,1466615025501-0.3661744,1466615025531-0.4646‌​7665,1466615025561-0.5533287,1466615025591-0.63311553,1466615025621-0.7049236,146‌​6615025652-0.7695509,1466615025681-1.7158673,1466615025711-1.6896278,146661502574‌​1-1.65375,1466615025772-1.6092329,1466615025801" print(re.sub("(?&lt;=,)(.{13})",r"\1"+",", s)) </code></pre> <p>Which will give you:</p> <pre><code>-0.1351197,1466615025472,-0.25672746,1466615025501,-0.3661744,1466615025531,-0.4646‌​7665,1466615025561,-0.5533287,1466615025591,-0.63311553,1466615025621,-0.7049236,146‌​6615025652-0.7695509,1466615025681,-1.7158673,1466615025711,-1.6896278,146661502574‌​1-1.65375,1466615025772,-1.6092329,1466615025801, </code></pre> <br /><br /><br /><h3>回答4:</h3><br /><p>I think you could do something like this:</p> <pre><code>direction = [] for line in open(filename): list = line.split(',') v = list[0] for s in list[1:]: t = s[:13] direction.append([float(v), long(t)]) v = s[13:] </code></pre> <p>If you're using python 3.X, then the long function no longer exists -- use int.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/37976716/python-read-txt-file-list</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/python" hreflang="zh-hans">python</a></div> <div class="field--item"><a href="/tag/list" hreflang="zh-hans">list</a></div> <div class="field--item"><a href="/tag/file" hreflang="zh-hans">file</a></div> <div class="field--item"><a href="/tag/python-3x" hreflang="zh-hans">python-3.x</a></div> <div class="field--item"><a href="/tag/readfile" hreflang="zh-hans">readfile</a></div> </div> </div> Thu, 28 Jan 2021 06:38:03 +0000 ぃ、小莉子 4028752 at https://www.e-learn.cn Reading the dynamic bitset written data from file cannot read the correct data https://www.e-learn.cn/topic/4019143 <span>Reading the dynamic bitset written data from file cannot read the correct data</span> <span><span lang="" about="/user/48" typeof="schema:Person" property="schema:name" datatype="">白昼怎懂夜的黑</span></span> <span>2021-01-27 20:57:35</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>So I have a vector which has three numbers. 65, 66, and 67. I am converting these numbers from int to binary and appending them in a string. the string becomes 100000110000101000011 (65, 66, 67 respectively). I am writing this data into a file through dynamic_bitset library. I have BitOperations class which does the reading and writing into file work. When I read the data from file instead of giving the above bits it gives me these 001100010100001000001 bits.</p> <p>Here is my BitOperations class:</p> <pre><code>#include &lt;iostream&gt; #include &lt;boost/dynamic_bitset.hpp&gt; #include &lt;fstream&gt; #include &lt;streambuf&gt; #include "Utility.h" using namespace std; using namespace boost; template &lt;typename T&gt; class BitOperations { private: T data; int size; dynamic_bitset&lt;unsigned char&gt; Bits; string fName; int bitSize; public: BitOperations(dynamic_bitset&lt;unsigned char&gt; b){ Bits = b; size = b.size(); } BitOperations(dynamic_bitset&lt;unsigned char&gt; b, string fName){ Bits = b; this-&gt;fName = fName; size = b.size(); } BitOperations(T data, string fName, int bitSize){ this-&gt;data = data; this-&gt;fName = fName; this-&gt;bitSize = bitSize; } BitOperations(int bitSize, string fName){ this-&gt;bitSize = bitSize; this-&gt;fName = fName; } void writeToFile(){ if (data != ""){ vector&lt;int&gt; bitTemp = extractIntegersFromBin(data); for (int i = 0; i &lt; bitTemp.size(); i++){ Bits.push_back(bitTemp[i]); } } ofstream output(fName, ios::binary| ios::app); ostream_iterator&lt;char&gt; osit(output); to_block_range(Bits, osit); cout &lt;&lt; "File Successfully modified" &lt;&lt; endl; } dynamic_bitset&lt;unsigned char&gt; readFromFile(){ ifstream input(fName); stringstream strStream; strStream &lt;&lt; input.rdbuf(); T str = strStream.str(); dynamic_bitset&lt;unsigned char&gt; b; for (int i = 0; i &lt; str.length(); i++){ for (int j = 0; j &lt; bitSize; ++j){ bool isSet = str[i] &amp; (1 &lt;&lt; j); b.push_back(isSet); } } return b; } }; </code></pre> <p>And here is the code which calls theses operations:</p> <pre><code>#include &lt;iostream&gt; // #include &lt;string.h&gt; #include &lt;boost/dynamic_bitset.hpp&gt; #include "Utility/BitOps.h" int main(){ vector&lt;int&gt; v; v.push_back(65); v.push_back(66); v.push_back(67); stringstream ss; string st; for (int i = 0; i &lt; v.size(); i++){ ss = toBinary(v[i]); st += ss.str().c_str(); cout &lt;&lt; i &lt;&lt; " )" &lt;&lt; st &lt;&lt; endl; } // reverse(st.begin(), st.end()); cout &lt;&lt; "Original: " &lt;&lt; st &lt;&lt; endl; BitOperations&lt;string&gt; b(st, "bits2.bin", 7); b.writeToFile(); BitOperations&lt;string&gt;c(7, "bits2.bin"); boost::dynamic_bitset&lt;unsigned char&gt; bits; bits = c.readFromFile(); string s; // for (int i = 0; i &lt; 16; i++){ to_string(bits, s); // reverse(s.begin(), s.end()); // } cout &lt;&lt; "Decompressed: " &lt;&lt; s &lt;&lt; endl; } </code></pre> <p>What am I doing wrong which results in incorrect behaviour?</p> <p>EDIT: Here is the extractIntegersFromBin(string s) function.</p> <pre><code>vector&lt;int&gt; extractIntegersFromBin(string s){ char tmp; vector&lt;int&gt; nums; for (int i = 0; s[i]; i++ ){ nums.push_back(s[i] - '0'); } return nums; } </code></pre> <p>Edit 2: Here is the code for toBinary:</p> <pre><code>stringstream toBinary(int n){ vector&lt;int&gt; bin, bin2; int i = 0; while (n &gt; 0){ bin.push_back(n % 2); n /= 2; i++; } // for (int j = i-1; j &gt;= 0; j--){ // bin2.push_back(bin[j]); // } reverse(bin.begin(), bin.end()); stringstream s; for (int i = 0; i &lt; bin.size(); i++){ s &lt;&lt; bin[i]; } return s; } </code></pre> <br /><h3>回答1:</h3><br /><p>You are facing two different issues:</p> <ol><li><p>The boost function <code>to_block_range</code> will pad the output to the internal block size, by appending zeros at the end. In your case, the internal block size is <code>sizeof(unsigned char)*8 == 8</code>. So if the bit sequence you write to the file in <code>writeToFile</code> is not a multiple of <code>8</code>, additional <code>0</code>s will be written to make for a multiple of <code>8</code>. So if you read the bit sequence back in with <code>readFromFile</code>, you have to find some way to remove the padding bits again.</p> </li> <li><p>There is no standard way for how to represent a bit sequence (reference). Depending on the scenario, it might be more convenient to represent the bits left-to-right or right-to-left (or some completely different order). For this reason, when you use different code pieces to print the same bit sequence and you want these code pieces to print the same result, you have to make sure that these code pieces agree on how to represent the bit sequence. If one piece of code prints left-to-right and the other right-to-left, you will get different results.</p> </li> </ol><p>Let's discuss each issue individually:</p> <h2>Regarding issue 1</h2> <p>I understand that you want to define your own block size with the <code>bitSize</code> variable, on top of the internal block size of <code>boost::dynamic_bitset</code>. For example, in your <code>main</code> method, you construct <code>BitOperations&lt;string&gt; c(7, "bits2.bin");</code>. I understand that to mean that you expect the bit seqence stored in the file to have a length that is some multiple of <code>7</code>.</p> <p>If this understanding is correct, you can remove the padding bits that have been inserted by <code>to_block_range</code> by reading the file size and then rounding it down to the nearest multiple of your block size. Though you should note that you currently do not enforce this contract in the <code>BitOperation</code> constructor or in <code>writeToFile</code> (i.e. by ensuring that the data size is a multiple of <code>7</code>).</p> <p>In your <code>readFromFile</code> method, first note that the inner loop incorrectly takes the <code>blockSize</code> into account. So if <code>blockSize</code> is <code>7</code>, this incorrectly only considers the first <code>7</code> bits of each block. Whereas the blocks that were written by <code>to_block_range</code> use the full <code>8</code> bit of each <code>1</code>-byte block, since <code>boost::dynamic_bitset</code> does not know anything about your <code>7</code>-bit block size. So this makes you miss some bits.</p> <p>Here is one example for how to fix your code:</p> <pre><code> size_t bitCount = (str.length()*8) / bitSize * bitSize; size_t bitsPerByte = 8; for (int i = 0; i &lt; bitCount; i++) { size_t index = (i / bitsPerByte); size_t offset = (i % bitsPerByte); bool isSet = (str[index] &amp; ( 1 &lt;&lt; offset)); b.push_back(isSet); } </code></pre> <p>This example first calculates how many bits should be read in total, by rounding down the file size to the nearest multiple of your block size. It then iterates over the full bytes in the input (i.e. the internal blocks that were written by <code>boost::dynamic_bitset</code>), until the targeted number of bits have been read. The remaining padding bits are discarded.</p> <p>An alternative method would be to use <code>boost::from_block_range</code>. This allows you to get rid of some boiler plate code (i.e. reading the input into some string buffer):</p> <pre><code> dynamic_bitset&lt;unsigned char&gt; readFromFile() { ifstream input{fName}; // Get file size input.seekg(0, ios_base::end); ssize_t fileSize{input.tellg()}; // TODO Handle error: fileSize &lt; 0 // Reset to beginning of file input.clear(); input.seekg(0); // Create bitset with desired size size_t bitsPerByte = 8; size_t bitCount = (fileSize * bitsPerByte) / bitSize * bitSize; dynamic_bitset&lt;unsigned char&gt; b{bitCount}; // TODO Handle error: fileSize != b.num_blocks() * b.bits_per_block / bitsPerByte // Read file into bitset std::istream_iterator&lt;char&gt; iter{input}; boost::from_block_range(iter, {}, b); return b; } </code></pre> <h2>Regarding issue 2</h2> <p>Once you have solved issue 1, the <code>boost::dynamic_bitset</code> that is written to the file by <code>writeToFile</code> will be the same as the one read by <code>readFromFile</code>. If you print both with the same method, the output will match. However, if you use different methods for printing, and these methods do not agree on the order in which to print the bits, you will get different results.</p> <p>For example, in the output of your program you can now see that the "Original:" output is the same as "Decompressed:", except in reverse order:</p> <pre><code>Original: 100000110000101000011 ... Decompressed: 110000101000011000001 </code></pre> <p>Again, this does not mean that <code>readFromFile</code> is working incorrectly, only that you are using different ways of printing the bit sequences.</p> <p>The output for <code>Original:</code> is obtained by directly printing the <code>0</code>/<code>1</code> input string in <code>main</code> from left to right. In <code>writeToFile</code>, this string is then decomposed in the same order with <code>extractIntegersFromBin</code> and each bit is passed to the <code>push_back</code> method of <code>boost::dynamic_bitset</code>. The <code>push_back</code> method appends to the end of the bit sequence, meaning it will interpret each bit you pass as more significant than the previous (reference):</p> <blockquote> <p>Effects: Increases the size of the bitset by one, and sets the value of the new most-significant bit to value.</p> </blockquote> <p>Therefore, your input string is interpreted such that the first bit in the input string is the least significant bit (i.e. the "first" bit of the sequence), and the last bit of the input string is the most significant bit (i.e. the "last" bit of the sequence).</p> <p>Whereas you construct the output for "Decompressed:" with <code>to_string</code>. From the documentation of this method, we can see that the least-significant bit of the bit sequence will be the <strong>last</strong> bit of the output string (reference):</p> <blockquote> <p>Effects: Copies a representation of b into the string s. A character in the string is '1' if the corresponding bit is set, and '0' if it is not. Character position i in the string corresponds to bit position b.size() - 1 - i.</p> </blockquote> <p>So the problem is simply that <code>to_string</code> (by design) prints in opposite order compared to the order in which you print the input string manually. So to fix this, you have to reverse one of these, i.e. by printing the input string by iterating over the string in reverse order, or by reversing the output of <code>to_string</code>.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/65547187/reading-the-dynamic-bitset-written-data-from-file-cannot-read-the-correct-data</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c-0" hreflang="zh-hans">c++</a></div> <div class="field--item"><a href="/tag/file" hreflang="zh-hans">file</a></div> <div class="field--item"><a href="/tag/readfile" hreflang="zh-hans">readfile</a></div> <div class="field--item"><a href="/tag/writefile" hreflang="zh-hans">writefile</a></div> <div class="field--item"><a href="/tag/boost-dynamic-bitset" hreflang="zh-hans">boost-dynamic-bitset</a></div> </div> </div> Wed, 27 Jan 2021 12:57:35 +0000 白昼怎懂夜的黑 4019143 at https://www.e-learn.cn How to read local files using HTML 5 FileReader? [duplicate] https://www.e-learn.cn/topic/4004563 <span>How to read local files using HTML 5 FileReader? [duplicate]</span> <span><span lang="" about="/user/33" typeof="schema:Person" property="schema:name" datatype="">被刻印的时光 ゝ</span></span> <span>2021-01-21 04:43:46</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><div> <aside class="s-notice s-notice__info js-post-notice mb16" role="status"><div class="grid fd-column fw-nowrap"> <div class="grid fw-nowrap"> <div class="grid--cell wmn0 fl1 lh-lg"> <div class="grid--cell fl1 lh-lg"> <b>This question already has answers here</b>: </div> </div> </div> <div class="grid--cell mb0 mt4"> Javascript read file without using input <span class="question-originals-answer-count"> (3 answers) </span> </div> <div class="grid--cell mb0 mt8">Closed <span title="2017-01-25 11:27:52Z" class="relativetime">3 years ago</span>.</div> </div> </aside></div> <h2>Objective</h2> <p>I am making an application, and I need to read a local file using JavaScript and HTML 5, without any <code>&lt;input&gt;</code> tags or user interaction whatsoever.</p> <h2>What I tried</h2> <p>On my research, I found two tutorials that are heavily cited in SO:</p> <ul><li>https://www.html5rocks.com/en/tutorials/file/dndfiles/</li> <li>http://blog.teamtreehouse.com/reading-files-using-the-html5-filereader-api</li> </ul><p>However, there is a problem. Both of this tutorials require user interaction via the <code>input</code> tag, which is a life killer since I want to read the contents of the file automatically into a string. </p> <h2>Code</h2> <p>So far I managed to get the following code:</p> <pre><code>let readFile = function(path) { let reader = new FileReader(); reader.onload = function(e) { var text = reader.result; console.log(text); }; // Read in the image file as a data URL. reader.readAsText(MissingFileHandle); }; </code></pre> <p>But as you can see, I am missing an important step, I am missing <code>MissingFileHandle</code>. My idea would be to pass a <code>path</code> to this method, and so the method would read the file locally as text and print it into the console, but I am unable to achieve this.</p> <h2>Question</h2> <p>Given a relative path, how can I read the contents of a file using HTML 5 without using <code>&lt;input&gt;</code> tags?</p> <br /><h3>回答1:</h3><br /><p>The HTML5 fileReader facility does allow you to process local files, but these MUST be selected by the user, you cannot go rooting about the users disk looking for files.</p> <p>Is it possible to load a file with JS/HTML5 FileReader on non served page?</p> <p>How to open a local disk file with Javascript?</p> <p>How to set a value to a file input in HTML?</p> <p>Javascript read file without using input</p> <p>These links help you to find answer.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>This Can do a trick.</p> <p>HTML </p> <pre><code> &lt;h1&gt;Text File Reader&lt;/h1&gt; &lt;div&gt; Select a text file: &lt;input type="file" id="fileInput"&gt; &lt;/div&gt; &lt;pre id="fileDisplayArea"&gt;&lt;pre&gt; &lt;/div&gt; </code></pre> <p>JS</p> <pre><code>window.onload = function() { var fileInput = document.getElementById('fileInput'); var fileDisplayArea = document.getElementById('fileDisplayArea'); fileInput.addEventListener('change', function(e) { var file = fileInput.files[0]; var textType = /text.*/; if (file.type.match(textType)) { var reader = new FileReader(); reader.onload = function(e) { fileDisplayArea.innerText = reader.result; } reader.readAsText(file); } else { fileDisplayArea.innerText = "File not supported!" } }); } </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/41849745/how-to-read-local-files-using-html-5-filereader</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/javascript" hreflang="zh-hans">javascript</a></div> <div class="field--item"><a href="/tag/html" hreflang="zh-hans">html</a></div> <div class="field--item"><a href="/tag/readfile" hreflang="zh-hans">readfile</a></div> </div> </div> Wed, 20 Jan 2021 20:43:46 +0000 被刻印的时光 ゝ 4004563 at https://www.e-learn.cn How to read local files using HTML 5 FileReader? [duplicate] https://www.e-learn.cn/topic/4004561 <span>How to read local files using HTML 5 FileReader? [duplicate]</span> <span><span lang="" about="/user/234" typeof="schema:Person" property="schema:name" datatype="">喜你入骨</span></span> <span>2021-01-21 04:42:26</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><div> <aside class="s-notice s-notice__info js-post-notice mb16" role="status"><div class="grid fd-column fw-nowrap"> <div class="grid fw-nowrap"> <div class="grid--cell wmn0 fl1 lh-lg"> <div class="grid--cell fl1 lh-lg"> <b>This question already has answers here</b>: </div> </div> </div> <div class="grid--cell mb0 mt4"> Javascript read file without using input <span class="question-originals-answer-count"> (3 answers) </span> </div> <div class="grid--cell mb0 mt8">Closed <span title="2017-01-25 11:27:52Z" class="relativetime">3 years ago</span>.</div> </div> </aside></div> <h2>Objective</h2> <p>I am making an application, and I need to read a local file using JavaScript and HTML 5, without any <code>&lt;input&gt;</code> tags or user interaction whatsoever.</p> <h2>What I tried</h2> <p>On my research, I found two tutorials that are heavily cited in SO:</p> <ul><li>https://www.html5rocks.com/en/tutorials/file/dndfiles/</li> <li>http://blog.teamtreehouse.com/reading-files-using-the-html5-filereader-api</li> </ul><p>However, there is a problem. Both of this tutorials require user interaction via the <code>input</code> tag, which is a life killer since I want to read the contents of the file automatically into a string. </p> <h2>Code</h2> <p>So far I managed to get the following code:</p> <pre><code>let readFile = function(path) { let reader = new FileReader(); reader.onload = function(e) { var text = reader.result; console.log(text); }; // Read in the image file as a data URL. reader.readAsText(MissingFileHandle); }; </code></pre> <p>But as you can see, I am missing an important step, I am missing <code>MissingFileHandle</code>. My idea would be to pass a <code>path</code> to this method, and so the method would read the file locally as text and print it into the console, but I am unable to achieve this.</p> <h2>Question</h2> <p>Given a relative path, how can I read the contents of a file using HTML 5 without using <code>&lt;input&gt;</code> tags?</p> <br /><h3>回答1:</h3><br /><p>The HTML5 fileReader facility does allow you to process local files, but these MUST be selected by the user, you cannot go rooting about the users disk looking for files.</p> <p>Is it possible to load a file with JS/HTML5 FileReader on non served page?</p> <p>How to open a local disk file with Javascript?</p> <p>How to set a value to a file input in HTML?</p> <p>Javascript read file without using input</p> <p>These links help you to find answer.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>This Can do a trick.</p> <p>HTML </p> <pre><code> &lt;h1&gt;Text File Reader&lt;/h1&gt; &lt;div&gt; Select a text file: &lt;input type="file" id="fileInput"&gt; &lt;/div&gt; &lt;pre id="fileDisplayArea"&gt;&lt;pre&gt; &lt;/div&gt; </code></pre> <p>JS</p> <pre><code>window.onload = function() { var fileInput = document.getElementById('fileInput'); var fileDisplayArea = document.getElementById('fileDisplayArea'); fileInput.addEventListener('change', function(e) { var file = fileInput.files[0]; var textType = /text.*/; if (file.type.match(textType)) { var reader = new FileReader(); reader.onload = function(e) { fileDisplayArea.innerText = reader.result; } reader.readAsText(file); } else { fileDisplayArea.innerText = "File not supported!" } }); } </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/41849745/how-to-read-local-files-using-html-5-filereader</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/javascript" hreflang="zh-hans">javascript</a></div> <div class="field--item"><a href="/tag/html" hreflang="zh-hans">html</a></div> <div class="field--item"><a href="/tag/readfile" hreflang="zh-hans">readfile</a></div> </div> </div> Wed, 20 Jan 2021 20:42:26 +0000 喜你入骨 4004561 at https://www.e-learn.cn