I have .txt file which contains data as follows [12,25],[36,45] i.e numbers are enclosed in square brackets separated by comma from each other I want to read such file through C++ program
I referred to string toolkit available,specifically regex facility can be used but i'm not able put in program can someone please help me??
To read from a text fileUse the ReadAllText method of the My. Computer. FileSystem object to read the contents of a text file into a string, supplying the path. The following example reads the contents of test.
Java FileReader class is used to read data from the file. It returns data in byte format like FileInputStream class. It is character-oriented class which is used for file handling in java.
You open a file by passing its filename – e.g. example. txt – into the open() function. The open() function returns a file object. To actually read the contents of a file, you call that file object's read() method.
Reading from a file There are three ways to read data from a text file. read() : Returns the read bytes in form of a string. Reads n bytes, if no n specified, reads the entire file.
just use scanf
or fscanf
like this:
if(scanf("[%d,%d]",&a[i],&b[i])==2){
++i;
while(scanf(",[%d,%d]",&a[i],&b[i])==2) ++i;
}
don't forget that C I/O functions are valid C++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With