How do you specify a line number with getline() (c++)

How do you specify which line for getline() to read with c++ similiar to how awk uses $1, $2, $3 , etc etc...
Example:(Ignore the underscores)
Line1 Line2
10____10
20____20
30____30
40____40
if I were making a program to remove 10 on the first line and 20 on the second line how would I tell getline which line to read
Example source code:
#include <cstdio>
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
int main()
string line;
string line2;
ifstream in("/Users/lundquisted/Desktop/infile.txt");
ofstream out("/Users/lundquisted/Desktop/outfile.txt");
while( getline(in,line) )
if(line != "10")
out << line << endl;
while (getline(in,line2) )
if(line2 != "20")
out << line2 << endl;
in.close();
out.close();
remove("/Users/lundquisted/Desktop/infile.txt");
rename("/Users/lundquisted/Desktop/outfile.txt","/Users/lundquisted/Desktop/inf ile.txt");
return 0;
}

Eric Lundquist wrote:
store the output of a system() command within a c++ program to a string and/or variable
A number of apps call Unix utilities and capture both stdout and stderr, typically for viewing in a log window, but for other uses as well. Xcode, for example, starts up gcc and does various things with the text that gcc might otherwise print in a Terminal window. Most apps that rely on Unix commands that way don't use "system()", which is a rather crude way of launching utilities that leaves the parent program with very little control. Usually, the best way to manage helper utils from a Cocoa app is by using NSTask and NSPipe. If you spend some time with the two following pages, you'll learn how to do almost anything you want with command line utils from inside a Cocoa app:
[http://www.cocoadevcentral.com/articles/000025.php]
[http://macosx.com/forums/archive/t-3927.html]
The first link goes to a great tutorial on using NSTask. Capturing stdout and stderr are only covered briefly towards the end, however. Note the last comment explaining why "system()" is a bad idea.
The second link goes to a forum thread. Scroll down to the code posted by "blb" for some very clear examples of launching with NSTask and reading the output with NSPipe.
If you really want to use a shell command, you could give NSTask a command like ' +bash -c "ls -lt | grep drwx"+ ' (see how setArguments: is used in the tutorial).
If you just want to do something cheap and dirty with "system()" so you can see some awk output while you're learning how to do things the right way, I guess you could do something like this:
system(" cat ~/random.txt | awk '{print $2}' > MyFile.txt");
NSString *myString = [NSString stringWithContentsOfFile:@"MyFile.txt"
encoding:NSUTF8StringEncoding error:nil];
Of course you can just read MyFile.txt into cin if you're not using Cocoa.
- Ray

Similar Messages

  • How do you register your mobile number with imessaging?

    When I want to send something to my phone from my ipod.. it won't regiser my mobile number? Why? Like I've tried, and it will only allow my e-mail to go threw.

    Turn off iMessage then turn it back on.
    You do have an iPhone and you are in the wrong place?
    If not, you can't send from your mobile number on your Touch.
    Message was edited by: deggie when I realized I was in the Touch forum.

  • How do you get a line with MULTIPLE fields to WRAP ?

    How do you get a line with MULTIPLE fields to WRAP ?
    Good afternoon everyone...
    THE PROBLEM: Why doesn’t a line with multiple fields WRAP?
    HYPOTHETICAL EXAMPLE/WHAT I”D LIKE TO SEE
    If I have 2 fields on a line (this is now a hypothetical example and nothing to do with my actual report)….let’s call them field A and field B. And if field A has values of all ‘X’ and field B has values of all ‘Y’…then….the normal case would be (ignore dots – only for spacing):
    A……………………… B
    XXXXXXXXXXXXXXXXXX YYYYYYYYYYYYYYYYY
    But what if A is too long? I would want to see B wrap onto the next line like this:
    A……………………………………………………B
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX YYYYYY
    YYYYYYYYYYYYY
    And similarly….if B is extra long, can the line print as:
    A………………………. B
    XXXXXXXXXXXXXXXXXXX YYYYYYYYYYYYYYYYYYYYYYYYYYY
    YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
    I don’t want the case where B is long and I get:
    A………………… …B…
    XXXXXXXXXXXXXXXXX YYYYYYYYYYYYYYYYYYYYYY
    ………………………..YYYYYYYYYYYYYYYYYYYYY
    I can see how you can wrap an individual field like that…but how can you WRAP a line of[b] fields within the frame so it wraps to the BEGINNING of the frame on next line?
    My SPECIFIC CASE
    I have a report that I have stripped down to a simple structure for the purposes of this explanation.
    My DATA MODEL has the main QUERY (for plant family and species data). The columns of the query are divided into 2 groups. The 1st GROUP contains the family data. Below that is the rest of the species data in a 2nd GROUP.
    Linking from the 2nd species group (above) is a new QUERY to extract REGION data based on the common key field. Under this 2nd query is another group with all the REGION columns.
    The LAYOUT MODEL has a group frame (the main , base one)
    On top of this is a repeating frame based on the 1st group (family data).
    On top of this is another repeating frame for the 2nd group (species data).
    On top of this is 2 Frames on the same line line. The 1st frame contains columns from the species group .
    The 2nd frame on this line is a repeating frame. The PRINT DIRECTION for this frame is ACROSS/DOWN. It repeats details of the REGION where the species is found. These columns come from this group come from the REGION QUERY and GROUP.
    All fields on the report line have variable horizontal elasticity.
    The problem is that when there is too much data on the line, it does NOT WRAP to the 2nd line.. It TRUNCATES.
    Can the line be made to WRAP????..
    In my current report, 1 of 2 things is happening:
    1) All fields print on the line until it hits the page boundary and then it just stops. Truncated!
    2) All fields print on the current line, then Oracle Reports throws a new page to print the REMAINDER of the long, input line
    But I would like a LONG line to continue printing onto the following line of the same page.
    I have tried all combinations of the elasticity fields and the ‘ADVANCED LAYOUT’ properties.
    I have been focussing my attention with this problem on the frames .
    We are using REPORT BUILDER V 6.0.8.26.0
    Thankyou to anyone who may offer assistance.
    Tony Calabrese.

    Steve,
    you gain 1 thing, but you lose something else!
    This thing is SO frustrating!
    Hey Steve! Good afternoon.
    I've done as you suggested....I have a long text boilerplate item - the only 1 on the line...and it has all the column in it.
    So it looks like:
    &col1 &col2 &col3 &col4 &col5 etc etc etc
    And the line expands nicely to each field's requirements.
    And when it gets to the right page boundary...it WRAPS to the next line! Beautiful!!!
    The only thing is that...when I had individual fields across the line I was able to create format triggers for those fields. And in doing so I was able to reduce the font and change the justification. I had to do that because some of the fields had to appear superscripted.
    So I wanted something like (ignore the dots):
    ...................................ppppp
    AAAA BBBB CCCCC DDDD EEEE FFFFFF
    So the field of 'ppppp' appeared slightly higher on the line than the other fields...
    I can't see how I can do this with a single TEXT field containing all the &COL values.
    Have you ever come across anything like this?
    Thankyou again,
    Tony Calabrese 12/4/2007

  • HT4061 How do you change your phone number than is in your iPad and replace it with right one to receive and send messages?

    How do you change your phone number in your iPad messages and replace it with another number. In order to send and receive messages to the correct phone number?

    It's best to use an email address on the iPad.
    Using FaceTime http://support.apple.com/kb/ht4319
    Troubleshooting FaceTime http://support.apple.com/kb/TS3367
    The Complete Guide to FaceTime + iMessage: Setup, Use, and Troubleshooting
    http://tinyurl.com/a7odey8
    Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/TS4268
    iOS: FaceTime is 'Unable to verify email because it is in use'
    http://support.apple.com/kb/TS3510
    Using FaceTime and iMessage behind a firewall
    http://support.apple.com/kb/HT4245
    iOS: About Messages
    http://support.apple.com/kb/HT3529
    Set up iMessage
    http://www.apple.com/ca/ios/messages/
    iOS 6 and OS X Mountain Lion: Link your phone number and Apple ID for use with FaceTime and iMessage
    http://support.apple.com/kb/HT5538
    How to Set Up & Use iMessage on iPhone, iPad, & iPod touch with iOS
    http://osxdaily.com/2011/10/18/set-up-imessage-on-iphone-ipad-ipod-touch-with-io s-5/
    Troubleshooting Messages
    http://support.apple.com/kb/TS2755
    Troubleshooting iMessage Issues: Some Useful Tips You Should Try
    http://www.igeeksblog.com/troubleshooting-imessage-issues/
    Setting Up Multiple iOS Devices for iMessage and Facetime
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l
    FaceTime and iMessage not accepting Apple ID password
    http://www.ilounge.com/index.php/articles/comments/facetime-and-imessage-not-acc epting-apple-id-password/
    FaceTime, Game Center, Messages: Troubleshooting sign in issues
    http://support.apple.com/kb/TS3970
    Unable to use FaceTime and iMessage with my apple ID
    https://discussions.apple.com/thread/4649373?tstart=90
    How to Block Someone on FaceTime
    http://www.ehow.com/how_10033185_block-someone-facetime.html
    My Facetime Doesn't Ring
    https://discussions.apple.com/message/19087457
    Send an iMessage as a Text Message Instead with a Quick Tap & Hold
    http://osxdaily.com/2012/11/18/send-imessage-as-text-message/
    To send messages to non-Apple devices, check out the TextFree app https://itunes.apple.com/us/app/text-free-textfree-sms-real/id399355755?mt=8
    How to Send SMS from iPad
    http://www.iskysoft.com/apple-ipad/send-sms-from-ipad.html
    You can check the status of the FaceTime/iMessage servers at this link.
    http://www.apple.com/support/systemstatus/
     Cheers, Tom

  • How to go to related line number

    hi all,
    Cause: FDPSTP failed due to ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at "APPS.WSH_UTIL_CORE", line 2093
    ORA-06512: at "APPS.UML_POS_ORDER_IMPORT_PKG", line 923
    This is package and I would like how can I go to line number 923 to check quick results.
    Thanks

    user9275313 wrote:
    hi all,
    Cause: FDPSTP failed due to ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at "APPS.WSH_UTIL_CORE", line 2093
    ORA-06512: at "APPS.UML_POS_ORDER_IMPORT_PKG", line 923
    This is package and I would like how can I go to line number 923 to check quick results.Open the package in the editor of your choice and use the editor's build in ability to go to the appropriate line.
    If the package is wrapped or a built in oracle package, you may struggle to open it, but then that would imply that either there's a bug in the package (ensure you're database is patched and check oracle support for known issues), or you're more likely calling procedures/functions in the package with the wrong parameters.

  • How do you remove a badge number from the app store without downloading...

    HOw do you remove the badge number icon for a program that you do not want to update from the app store.
    I have an app that is updated but i don't want the update (new ugly artwork and I am content with what the present artwork and app does)...I don't want the update. How do I remove/refuse the update and remove the number badge?
    Thanks!

    so you have an app on your phone that you do not want to update?
    But you want to get rid of that annoying badge from the appstore?
    There is a fix for this!
    Created by Elit3!
    if you post this anywhere else please acknowledge my find! thank you.
    new directions:
    1. go to itunes
    2. click applications
    3. right click on the application you want to use
    4. press show in windows explorer
    5. Copy the ipa to desktop
    6. right click and press open with
    7. open file with winrar, winzip, what ever, something so you can see all the files
    8. open iTunesMetadata.plist with PLIST EDITOR
    9. search for "itemId"
    10. Delete the number under "itemId" in between </integer>
    11. leave One number remaining. (any number)
    12. save.
    13. double click your new ipa
    14. sync
    15. No more update badge
    DONE.
    remember to backup everything you change. just in case.

  • How do you compile Flex-dependent classes with ASC?

    Hi,
    I've been trying unsuccessfully for most of the evening to compile a .as file that relies on mx.collections.ListCollectionView using asc. I figured I could just import the Flex framework SWCs from the command line with asc, but asc doesn't seem to respect SWCs - it only seems to respect .abc files.
    So, I've spent most of my time trying to compile the Flex framework into a single .abc file that I can import whenever I want to compile a class that relies on Flex. I figured I could make a base .as file with include statements for all of the Flex .as files (copying the approach I saw for files like builtin.as) and compile that, but all I seem to get are compiler errors - mostly "[Compiler] Error #1181: Forward reference to base class (base class name)."
    I have a feeling I'm doing this completely the wrong way. I'd very much appreciate any assistance that anybody can offer me.
    Thanks,
    - max

    <div class=Section1><br /><br /><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";<br />color:#1F497D'>I use MXMLC to compile my .as file projects.<o:p></o:p></span></p><br /><br /><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";<br />color:#1F497D'><o:p> </o:p></span></p><br /><br /><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";<br />color:#1F497D'>Alex Harui<o:p></o:p></span></p><br /><br /><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";<br />color:#1F497D'>Flex SDK Developer<o:p></o:p></span></p><br /><br /><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";<br />color:#1F497D'><a href="http://www.adobe.com/"><span style='color:blue'>Adobe<br />Systems Inc.</span></a><o:p></o:p></span></p><br /><br /><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";<br />color:#1F497D'>Blog: <a href="http://blogs.adobe.com/aharui"><span<br />style='color:blue'>http://blogs.adobe.com/aharui</span></a><o:p></o:p></span></p><br /><br /><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";<br />color:#1F497D'><o:p> </o:p></span></p><br /><br /><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><br /><br /><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span<br />style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Maxim Porges<br />[mailto:[email protected]] <br><br /><b>Sent:</b> Monday, February 09, 2009 9:22 PM<br><br /><b>To:</b> [email protected]<br><br /><b>Subject:</b> How do you compile Flex-dependent classes with ASC?<o:p></o:p></span></p><br /><br /></div><br /><br /><p class=MsoNormal><o:p> </o:p></p><br /><br /><p class=MsoNormal style='margin-bottom:12.0pt'>A new discussion was started by<br />Maxim Porges in <br><br /><br><br /><b>Developers</b> --<br><br />  How do you compile Flex-dependent classes with ASC?<br><br /><br><br />Hi, <br><br /><br><br />I've been trying unsuccessfully for most of the evening to compile a .as file<br />that relies on mx.collections.ListCollectionView using asc. I figured I could<br />just import the Flex framework SWCs from the command line with asc, but asc<br />doesn't seem to respect SWCs - it only seems to respect .abc files. <br><br /><br><br />So, I've spent most of my time trying to compile the Flex framework into a<br />single .abc file that I can import whenever I want to compile a class that<br />relies on Flex. I figured I could make a base .as file with include statements<br />for all of the Flex .as files (copying the approach I saw for files like<br />builtin.as) and compile that, but all I seem to get are compiler errors -<br />mostly &quot;[Compiler] Error #1181: Forward reference to base class (base<br />class name).&quot; <br><br /><br><br />I have a feeling I'm doing this completely the wrong way. I'd very much<br />appreciate any assistance that anybody can offer me. <br><br /><br><br />Thanks, <br><br /><br><br />- max <o:p></o:p></p><br /><br /><div class=MsoNormal><br /><br /><hr size=2 width=200 style='width:150.0pt' align=left><br /><br /></div><br /><br /><p class=MsoNormal style='margin-bottom:12.0pt'>View/reply at <a<br />href="http://www.adobeforums.com/webx?13@@.59b7d5d2">How do you compile<br />Flex-dependent classes with ASC?</a><br><br />Replies by email are OK.<br><br />Use the <a<br />href="http://www.adobeforums.com/webx?280@@.59b7d5d2!folder=.3c060fa3">unsubscribe</a>< br />form to cancel your email subscription.<o:p></o:p></p><br /><br /></div>

  • How do you find your phone number?

    How do you find your phone number?

    You can't.  The iPod tuch does not have a phone number.  For the Messages and FaceTime apps you use the email address that yu set them up with.  With some oher texting apps like Text+, the apps assign you a phone number.

  • How do you use new ipod nano with itunes 10.6.3?

    How do you use new ipod nano with Itunes 10.6.3.  I have MBP and it lists itunes 10.6.3 as most current version and won't let me install itunes 11

    The seventh generation iPod nano requires at least iTunes 10.7 and Mac OS X 10.6.
    (85225)

  • My 3rd iphone. 3GS I did not buy from an apple store, how do I register this serial number with my apple account? it is already sync to it and will preform every function except email to my home computer. It says apple ID disabled

    My 3rd iphone is a 3GS. I did not buy this one from the apple store, how do I register this serial number with my apple account? it is already sync'd and it and will preform every function except email to my home computer. It says apple ID disabled, also will not update my apps, same promt apple id disabled.
    anyone know where I can go to register this phone? Thanks

    https://register.apple.com

  • How can you change your line access selection?  I have found where you can change your plan selection, but can you change the line access fee or is that a set amount?

    How can you change your line access selection?  I have found where you can change your plan selection, but can you change the line access fee or is that a set amount?

        DIVAB71,
    Great question. The line access fees for the account are a set amount and can not be changed unless you are going from a basic to a smartphone or vice versa. If you are wondering about adding the month to month discount if you are out of contract Ann154 has provided great information on how to access and add the feature.
    LindseyT_VZW
    Follow us on Twitter @VZWSupport

  • How do you specify what format you want the song to download in?

    How do you specify what format you want the song to download in?

    In preferences set up your import settings, then right click on the tracks you need in a different format and use Create < Format> Version. New copies will be created in the target format.
    tt2

  • HT4113 how do you hard reset 2nd gen with out pass code?

    how do you hard reset a ipad with out the password

    Locked Out, Forgot Lock or Restrictions Passcode, or Need to Restore Your Device: Several Alternative Solutions
    A
    1. iOS- Forgotten passcode or device disabled after entering wrong passcode
    2. iPhone, iPad, iPod touch: Wrong passcode results in red disabled screen
    3. Restoring iPod touch after forgotten passcode
    4. What to Do If You've Forgotten Your iPhone's Passcode
    5. iOS- Understanding passcodes
    6. iTunes 10 for Mac- Update and restore software on iPod, iPhone, or iPad
    7. iOS - Unable to update or restore
    Forgotten Restrictions Passcode Help
                iPad,iPod,iPod Touch Recovery Mode
    You will need to restore your device as New to remove a Restrictions passcode. Go through the normal process to restore your device, but when you see the options to restore as New or from a backup, be sure to choose New.
    You can restore from a backup if you have one from BEFORE you set the restrictions passcode.
    Also, see iTunes- Restoring iOS software.

  • How do you view lyrics on itouch with the new Jan. software update??

    How do you view lyrics on itouch with the new Jan. software update??
    Thanks!!

    1) You need to have the paid upgrade installed.
    2) You need to paste the lyrics into the lyrics tab of a song/album.
    3) You need to re-sync the Touch.
    4) When playing music, you click on the album cover (in portrait mode only) and the lyrics will superimpose on the screen.
    Scott
    Message was edited by: A A P L

  • How do you change the phone number on an ipad mini in the imessage settings?

    How do you change the phone number on an ipad mini in the imessage settings?

    The Phone number of a Cellular iPad is assigned by the carrier the iPad is connected to.  Usually changing the sim card will change this number.
    If that is not what you mean can you please explain in more detail

Maybe you are looking for

  • Can I get a time machine hard drive to restore onto Windows XP?

    Yeah, I just bought an iMac and I figured why not sell my Mac Mini? So I have time machine on and I back up all my files to my external hard drive of course. Now, sense I am selling my Mac Mini, I need to use Windows XP on my old PC for a month cause

  • How do I remove a blank line in a pdf with  adobe pro XI?

    How do I remove a blank line in a pdf with adobe pro XI? Can I combine text blocks into one paragraph that are now given line by line? Is there a way to add a paragraph to an existing pdf and have the remaining text flow to the next pages?

  • Adobe PDF printer freezes on my Win 7 x64 with Acrobat XI

    Purchased and running Acrobat XI Standard latest update 11.0.10 on Win 7 Pro x64 (6.1.7601  Service Pack 1), a rather fresh installation (2 months). Adobe's conversion to PDF doesn't work when using the Adobe PDF printer. The printer initiates normal

  • VOB files

    Hi, I am trying to copy a DVD that A friend made of a gig my band did. What I want to do is make something in either idvd or imovie with a menu and chapters 7 then burn it to disc. My problem is that the files on the disc are things like VIDEO_TS.BUP

  • N8 - Service is unavailable

    Hello, I'm using N8. I'm trying to update my Nokia Belle using my computer but still cannot. I'm using Nokia Suite 3.3.89. When I try to update, the message is 'Service is unavailable'. May I know why this happen...?