file-handling

whether tellp() not defined in append mode?

試著忘記壹切 提交于 2019-12-05 14:48:51
I was experimenting with file pointers in C++. In below code, the result obtained is 0, 30, 10 and 12. So it means that tellp() does not give correct result in append mode if we do seekp(). I was expecting tellp() to give me 32 after seekp() and appending data. I understand that in app mode, writing is always to the end and hence got this doubt. Does the result mean that tellp() position does not matter in append mode? The contents of h1.txt file is : 01234567891011121314151617181911 and is is as expected. ofstream f1("h1.txt",ios::app|ios::out); if (!f1) { cerr<<"cannot open the file\n"; exit

Why do I get a SIGABRT here?

你离开我真会死。 提交于 2019-12-04 23:02:18
I have this code segment in which I am opening/closing a file a number of times (in a loop): for(i=1;i<max;i++) { /* other code */ plot_file=fopen("all_fitness.out","w"); for (j=0;j<pop_size;j++) fprintf(plot_file, "%lf %lf\n",oldpop[i].xreal[0],oldpop[i].obj); fclose(plot_file); /*other code*/ } I get a SIGABRT here, with the following backtrace: #0 0x001fc422 in __kernel_vsyscall () #1 0x002274d1 in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64 #2 0x0022a932 in *__GI_abort () at abort.c:92 #3 0x0025dee5 in __libc_message (do_abort=2, fmt=0x321578 "*** glibc detected ***

Read comma separated values from a text file in C [duplicate]

血红的双手。 提交于 2019-12-04 19:53:15
This question already has answers here : read comma-separated input with scanf (2 answers) Read .CSV file in C (4 answers) Closed 12 months ago . I am really new to C programming and this is a part of an assignment. I am trying to read a comma separated text file in the format: [value1], [value2] in C and trying to pass them as string and int parameter into a function. I have tried using the sscanf() and even manipulation with fgetc() without much help. The space after the comma is proving to be a problem. Example: 2001, 102 1314, 78 0410, 910 ... Please help me out. Thank you. Thanks to

Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile] for property

放肆的年华 提交于 2019-12-04 18:49:25
I am saving an image file from jsp and renaming it in the controller The problem is that same piece of code is working in one part of the controller and not working in another part of the controller here is the jsp code which is same in both cases:- <div class="form-group "> <label for="photo">Photo:</label> <form:input type="file" class="filestyle" path="studentPhoto" id="studentPhoto" placeholder="Upload Photo" required="required" /> </div> Here is the part of the controller where it is working as expected:- @RequestMapping(value = "/student", params = "add", method = RequestMethod.POST)

How to extract data from a line which has fields separated by '|' character in C++?

家住魔仙堡 提交于 2019-12-04 14:03:01
问题 I have data in the following format in a text file. Filename - empdata.txt Note that there are no blank space between the lines. Sl|EmployeeID|Name|Department|Band|Location 1|327427|Brock Mcneil|Research and Development|U2|Pune 2|310456|Acton Golden|Advertising|P3|Hyderabad 3|305540|Hollee Camacho|Payroll|U3|Bangalore 4|218801|Simone Myers|Public Relations|U3|Pune 5|144051|Eaton Benson|Advertising|P1|Chennai I have a class like this class empdata { public: int sl,empNO; char name[20]

Parsing a flat file in Java

笑着哭i 提交于 2019-12-04 11:52:50
I have a flat file in which data is stored in position based format For eg. from 1 to 5 - some x value is stored, from 6 to 13 - some y value is stored, from 14 to 18 - some z value is stored and so on.. I need to parse the file and get those values and populate a bean. Can anyone please tell me the best way I can go about it means how I can parse the file.I am using Java 6. Non complex, fixed length rows should be very easy in plain java. Why don't you just use plain basic substring? I've seen this used in parsing quite big flat files, and it's not as bad as it sounds. Pretty easy to get an

C++ Program crashes when reading object from random access file

空扰寡人 提交于 2019-12-04 06:22:05
问题 I have the following User.h that holds several attributes (strings). User.cpp has all the definitions. //User.h #ifndef USER_H #define USER_H #include<iostream> #include <cstring> using namespace std; class User{ string username; public: User(); string getUsername() const; void setUsername(string); }; #endif I'm using a another class, "File" to insert new users/view users from a randomly accessed .dat file //File.h #ifndef FILE_H #define FILE_H #include "User.h" class File{ public: void

How to read .lbl file

自闭症网瘾萝莉.ら 提交于 2019-12-04 06:02:17
问题 I want to read my .lbl file and store its data into a database column. So, whenever the user wants to modify it, they may create a new .lbl file from the Database. I have converted my .lbl data into Binary by using the snippet shown below: byte[] fileBytes = File.ReadAllBytes("D:\\Work\\PNS\\TEST.lbl"); StringBuilder sb = new StringBuilder(); foreach (byte b in fileBytes) { sb.Append(Convert.ToString(b, 2).PadLeft(8, '0')); string bindata = sb.ToString(); // store this variable value in

does fopen return NULL pointer if file is already open

徘徊边缘 提交于 2019-12-04 05:51:17
问题 I was assuming that fopen returns NULL pointer if file is already open. But it looks fopen does not return NULL in case file is already open in "w" mode. Below is the code that I used to try this and I do not get any errors. I tried with mingw32 as well as TDM-GCC-64 compilers. If I am not mistaken, C++ gives error if file is already open. #include<stdio.h> int main() { FILE *fp1, *fp2; fp1=fopen("file1.txt", "w"); fp2=fopen("file1.txt", "w"); if(fp2==NULL) { printf("Error in opening file\n")

How to write a file in external sd card and not in device storage?

折月煮酒 提交于 2019-12-04 04:08:11
问题 I tried this: public String getFilename() { File file = new File(Environment.getExternalStorageDirectory(), "Test2"); if (!file.exists()) { file.mkdirs(); } String uriSting = (file.getAbsolutePath() + "/" + "IMG_" + System.currentTimeMillis() + ".png"); return uriSting; } I tried changing the second line to: File file = new File("sdcard/Test2"); But still the directory is being created in device storage and not on external sd card. 回答1: You do not have arbitrary access to removable storage.