text-files

C++ delete last character in a txt file

拈花ヽ惹草 提交于 2019-12-01 08:18:34
I need some help on deleting the last character in a txt file. For example, if my txt file contains 1234567, I need the C++ code to delete the last character so that the file becomes 123456. Thanks guys. The only way to do this in portable code is to read in the data, and write out all but the last character. If you don't mind non-portable code, most systems provide ways to truncate a file. The traditional Unix method is to seek to the place you want the file to end, and then do a write of 0 bytes to the file at that point. On Windows, you can use SetEndOfFile. Other systems will use different

\\n won't work, not going to a new line

与世无争的帅哥 提交于 2019-12-01 06:55:32
I'm creating a small program that saves a int value into a text file, saves it, and loads it when you start the program again. Now, I need 3 more booleans to be stored in the text file, I am writing things in the file with public Formatter x; x.format("%s", "" + m.getPoints() + "\n"); Whenever I want to go to a new line in my text file, with \n, it wont go to a new line, it will just write it directly behind the int value. I tried doing both x.format("%s", "" + m.getPoints() + "\n"); x.format("%s", "" + m.getStoreItem1Bought() + "\n"); and x.format("%s%s", "" + m.getPoints() + "\n", "" + m

Preserving newline characters in data:text URI

爷,独闯天下 提交于 2019-12-01 05:43:32
问题 I have a button in my extension that triggers the following code: chrome.tabs.create({url: 'data:text;base64,'+btoa(data), active:false}); This triggers a download of my string (data), as I expected. Unfortunately, it seems to be stripping out newline characters. I have tried other encoding methods, including utf-8 and the encodeUri() function. I also tried switching the mimetype to data:text/plain , but that simply opens in a new tab (with the correct newline characters) instead of

How to read a single word (or line) from a text file Java?

家住魔仙堡 提交于 2019-12-01 05:34:34
Like the title says, im trying to write a program that can read individual words from a text file and store them to String variables. I know how to use a FileReader or FileInputStream to read a single char but for what I'm trying to this wont work. Once I input the words I am trying to compare these with other String variables in my program using .equals so it would be best if I can import as Strings. I am also okay with inputting an entire line from a text file as a String in which case Ill just put one word on each line of my file. How do I input words from a text file and store them to

C# - Load a text file as a class

荒凉一梦 提交于 2019-12-01 05:31:19
Is there any way to load a .txt file as a class, which my main program can then call functions from? I'm basically trying to add mod support to my simple app, where the user can select options from each file. The file follows a similar (but not the same) format, with a bunch of voids (functions) that are called in the main program. How can I do this? Is that even possible to do (probably not, answering my own question?), considering it wouldn't be compiled along with the rest of the program? Thanks! Tim Medora See me answer to this question: Compile a C# Array at runtime and use it in code?

Error incomplete universal character name \\U

妖精的绣舞 提交于 2019-12-01 05:12:19
I'm trying to write a C++ program that alters a .txt file. However when I run it I get a strange error. The error: 6:20 C:\Dev-Cpp\Homework6.cpp incomplete universal character name \U My code: #include <iostream> #include <fstream> using namespace std; int main () { ofstream myfile ("C:\Users\My Name\Desktop\test\input.txt"); if (myfile.is_open()) { myfile << "This is a line.\n"; myfile << "This is another line.\n"; myfile.close(); } else cout << "Unable to open file"; return 0; } What am I doing wrong? "C:\Users\My Name\Desktop\test\input.txt" The backslash ( \ ) is a special character. You

Importing a txt file when number of columns varies?

若如初见. 提交于 2019-12-01 04:46:44
I have problems importing a .txt file into R because the number columns changes from eight to nine. Initially, my data has eight columns: Date, Open, High, Low, Close, Volume, Open Interest, Delivery Month Later, I add an additional column Unadjusted close . How should I import the data? Somehow the Unadjusted close column has to be ignored at the beginning. I've tried data1 <- read.table("AD_0.TXT", sep=",", header=TRUE) but that doesn't work. You need to use the fill argument in the read.table function. Suppose I have the following file "A","B","C" 1,2,3 4,5 6,7,8 called tmp.txt . Note that

OutputStreamWriter does not append

孤者浪人 提交于 2019-12-01 03:55:01
Original code and its working saving the data to the SD Card // Writing data to internal storage btnSaveData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isSDCardWritable()) { String dataToSave = etData.getText().toString(); try { // SD Card Storage File sdCard = Environment.getExternalStorageDirectory(); File directory = new File(sdCard.getAbsolutePath()+"/MyFiles"); directory.mkdirs(); File file = new File(directory, "text.txt"); FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fos); // write the

C# - Load a text file as a class

强颜欢笑 提交于 2019-12-01 03:12:52
问题 Is there any way to load a .txt file as a class, which my main program can then call functions from? I'm basically trying to add mod support to my simple app, where the user can select options from each file. The file follows a similar (but not the same) format, with a bunch of voids (functions) that are called in the main program. How can I do this? Is that even possible to do (probably not, answering my own question?), considering it wouldn't be compiled along with the rest of the program?

How to read a single word (or line) from a text file Java?

天涯浪子 提交于 2019-12-01 03:12:08
问题 Like the title says, im trying to write a program that can read individual words from a text file and store them to String variables. I know how to use a FileReader or FileInputStream to read a single char but for what I'm trying to this wont work. Once I input the words I am trying to compare these with other String variables in my program using .equals so it would be best if I can import as Strings. I am also okay with inputting an entire line from a text file as a String in which case Ill