How can I open a file, skip first 2 lines and get the 50th character?
EXP 0 R:\000\un\111\e00\e00noLog\1006\bdry_arc.e00
ARC 2
1 1 0 0 0 0 7
i.e., I want to get the "7" in the third line, how can I do that?
thx!! 7 11602
Hi,
#include <fstream>
#include <string>
using namespace std;
int main()
{
int RetVal = 0;
ofstream Input( "Filename" );
if( !Input.is_open() )
{
// Could use exceptions, but since it is so small...
RetVal = 1;
}
else
{
string Line;
getline( Input, Line );
getline( Input, Line );
getline( Input, Line );
cout << Input[ 49 ] << endl;
}
return RetVal;
}
TODO add some more error checking.
Regards, Ron AF Greve.
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote in message
news:bm***********@news.hgc.com.hk... How can I open a file, skip first 2 lines and get the 50th character?
EXP 0 R:\000\un\111\e00\e00noLog\1006\bdry_arc.e00 ARC 2 1 1 0 0 0 0 7
i.e., I want to get the "7" in the third line, how can I do that?
thx!!
Oops in my previous post that should be ifstream of course.
Regards, Ron AF Greve.
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote in message
news:bm***********@news.hgc.com.hk... How can I open a file, skip first 2 lines and get the 50th character?
EXP 0 R:\000\un\111\e00\e00noLog\1006\bdry_arc.e00 ARC 2 1 1 0 0 0 0 7
i.e., I want to get the "7" in the third line, how can I do that?
thx!!
"FrancisC" <fr**********@hong-kong.crosswinds.net> writes: How can I open a file, skip first 2 lines and get the 50th character?
EXP 0 R:\000\un\111\e00\e00noLog\1006\bdry_arc.e00 ARC 2 1 1 0 0 0 0 7
i.e., I want to get the "7" in the third line, how can I do that?
The 7 is the 70th character on this line, not the 50th.
Some things are better done with standard unix tools than reinvented:
head -3 bla | tail -1 | cut -b 50
kind regards
frank
--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote in message news:<bm***********@news.hgc.com.hk>... How can I open a file, skip first 2 lines and get the 50th character?
std::ifstream in("file.name");
std::istreambuf_iterator<char> beg(in), end;
beg = std::find(std::find(beg, end, '\n'), end, '\n');
for (int i = 0; i < 50 && beg != end; ++beg)
;
if (beg != end)
std::cout << "the 50th character on the third line is '"
<< *beg << "'\n";
else
std::cout << "some error occured while looking for the character\n";
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>
Hi
Now without the typo's ;-)
#include <fstream>
#include <string>
using namespace std;
int main()
{
int RetVal = 0;
ifstream Input( "Filename" );
if( !Input.is_open() )
{
// Could use exceptions, but since it is so small...
RetVal = 1;
}
else
{
string Line;
getline( Input, Line );
getline( Input, Line );
getline( Input, Line );
cout << Line[ 49 ] << endl;
}
return RetVal;
}
FrancisC wrote: How can I open a file, skip first 2 lines and get the 50th character?
I recommend you decide which language you are working in. This same
question appeared in comp.lang.c.
Brian Rodenborn
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote in message
news:bm***********@news.hgc.com.hk... How can I open a file, skip first 2 lines and get the 50th character?
EXP 0 R:\000\un\111\e00\e00noLog\1006\bdry_arc.e00 ARC 2 1 1 0 0 0 0 7
i.e., I want to get the "7" in the third line, how can I do that?
thx!!
one way:
1) Open the file for reading
2) Read the first line into a string
3) Read the next line into the same string
4) Read the third line into the same string
5) The character you want is in the string...just use it! (i.e.,
myString[49])
-Howard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: gary smith |
last post by:
I am trying to open a file (file --> open --> file) at an FTP location using
visual Studio.net. Unfortunately, I get an "unspecified error" alert
whenever I select a file.
Can anyone help...
|
by: puzzlecracker |
last post by:
I want to read lines and skip blank lines:
would this work considering the lines can contain tabs, spaces, etc.?
file.in:
------
line1
line2
|
by: Corne' Cornelius |
last post by:
Hi,
When you open a file for writing/appending with open() or fopen(), and
you have multiple applications that might want to write to the same file
at the same time, could that cause weirdness...
|
by: FrancisC |
last post by:
How can I open a file, skip first 2 lines and get the 50th character?
EXP 0 R:\000\un\111\e00\e00noLog\1006\bdry_arc.e00
ARC 2
1 1 0 0 0 0 7
...
|
by: agphoto |
last post by:
There is big or problem in open file in read and write mode..
$file = "data.txt";
$fp = fopen($file,"w+");
$line = fgets($fp,"120"); // i need only 1st line to read and upto 120 bytes
echo...
|
by: Ryan Liu |
last post by:
Hi,
Both way works, I'd just ask some experts which way is better?
My application creates a log file daily.
Now each time when I write a log, I will open the file and append to the
end....
|
by: gonzlobo |
last post by:
I've been using Python for a few days. It's such the perfect language
for parsing data!
I really like it so far, but I'm having a hard time reading a file,
reading the first few hex characters &...
|
by: tjuiowa |
last post by:
Hi
I am trying to import a text file into a MS Access database. The first 11 lines of the text file are in a different format, so i would like to skip those lines and start at line 12. is there...
|
by: luckyyyyyy |
last post by:
I appriate your work but...
guys i have another problm.....i wana skip first 9 lines from my data file and after skipping i wana read x,y,z at the end of file. i did but after while loop is end it...
|
by: JeremyI |
last post by:
Today I've been trying out a personal project I have been interested in for a while. MS Access 2000.
I get a daily list of currency exchange rates via email, but it's a bit of a pain to go through...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| | |