[Solved] How can I store a variable in another file?

You can use std::fstream: #include <fstream> #include <iostream> int myint; int main() { // when entering app: std::ifstream fs(“data.txt”); if ( fs ) { fs >> myint; } fs.close(); std::cout << myint; myint++; // when exiting app: std::ofstream fs2(“data.txt”); fs2 << myint; } 2 solved How can I store a variable in another file?

[Solved] How to print selected elements from file?

Here is one way: with open(“fk.txt”) as file: # Use file to refer to the file object data = file.readlines() column1, column2 = [], [] for line in data: try: entry1, entry2 = line.split(‘ ‘) column1.append(int(entry1)) column2.append(int(entry2)) except ValueError: pass print column1, column2 2 solved How to print selected elements from file?

[Solved] Cannot create a txt file using fstream::open

Point 1: You cannot open to read if the file doesn’t exist. Fortunately you probably don’t want to. Simultaneously reading and writing the same file is problematic and almost always a bad idea. Until you know you have to read and write at the same time, open the file for reading read in the file … Read more

[Solved] How to print selected elements from file?

Introduction Printing selected elements from a file can be a useful way to quickly access the information you need. Whether you are looking to print out a specific line from a text file or a specific column from a CSV file, there are a few different methods you can use to achieve this. In this … Read more

[Solved] Issue with substr C++

As mentioned you can’t call substr() with a std::ifstream. What you probably meant was to take the parts from the line string read in a[i]= stoi(line.substr(4,2)); name[i]= line.substr(18,15); b[i]= stoi(line.substr(36,1)); Also note you’ll need to convert the substrings extracted to a number (instead of assigning them directly), hence I have added the stoi(). As also … Read more

[Solved] How to only print file contents if there are 10 more lines? [closed]

you can do something like this: BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(“path”)); String line = null; int count = 0; while ((reader.readLine()) != null && count < 11) { count++; } if (count > 10) { reader = new BufferedReader(new FileReader(“path”)); while ((line = reader.readLine()) != null) { System.out.println(line); } … Read more

[Solved] Not able to get sum of array in C#

Your error is from these lines: Console.WriteLine(rea.ReadLine()); ad.Add(Int32.Parse(rea.ReadLine())); What’s happening is you are getting the count of the number of lines in the file. Say your file has 10 lines. When the loop reaches the last line and you call ReadLine method in Console.WriteLine(rea.ReadLine());, it returns the last line. But then you call Readline method … Read more

[Solved] File.Exists is working in C#, but doesn’t work in VB.NET

Try this way: Dim stringData As String = GetFolderPath(SpecialFolder.MyDocuments) & “\my.exe” ‘For example If Not String.IsNullOrEmpty(stringData) Then If File.Exists(stringData) Then Process.Start(stringData) Else MsgBox(“File couldn’t be found.”, vbCritical, “MyApp”) End If End If solved File.Exists is working in C#, but doesn’t work in VB.NET

[Solved] $_FILES[“file”][“name”] is returning empty value [closed]

In your case the problem is the following line: header(‘Location: ‘.$redirect); When you first run move_uploaded_file and then make redirection using header function, $_FILES array gets empty, so in next line simple you cannot check $_FILES anymore. In addition I don’t see any point making this redirectrion. When you move_uploaded_file it simple return true on … Read more

[Solved] How to populate Objects in a an existing file [closed]

class People: def __init__(self, fname=None, lname=None, age=None, gender=None): self.fname = fname self.lname = lname self.age = age self.gender = gender def display(self): print self.fname people = [People(‘John’,’W Cooper’,23,’Male’), People(‘James’,’W Cooper’,30,’Male’), People(‘Kate’,’W Cooper’,20,’Female’)] f = open(“abc.txt”, “w”) for person in people: f.write( person.fname +”,”+ person.lname +”,”+ str(person.age) +”,”+ person.gender + ‘\n’ ) person.display() f.close() 5 solved … Read more