Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2007

Tip: Looking for answers? Try searching our database.

File Access and variable usage/manipulation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy - 08 Feb 2007 22:22 GMT
Hello,

I'm trying to create a C++ command line program that will extract specific
lines from a text file and write them to another text file. E.g. If I want
the program to look for the word "The"(Always at the start) and extract the
entire line.
Text file input example:
// ------------------------
Hello there!
The quick brown fox

Jumped over the
lazy dog
The pizza arrived
on time
// ------------------------

Would output

The quick brown fox
The pizza arrived

I know this can be done with VB using strings and InStr. I've found that
strings can be examined using
string.find(word to find);
However, when reading data from a file, I don't seem to be able to use a
string to put the data read from a file into.
I've tried using

// -------
ifstream filein;
filein >> variable;
// And
filein.read(variable, character-limit);
// -------

Neither appears to accept using a string variable as a variable for that, I
can get it to work as a char, double, etc; but when I use char I stops at
spaces and ignores the ends of lines.

Thank you,
Andy.
Tamas Demjen - 08 Feb 2007 22:44 GMT
> However, when reading data from a file, I don't seem to be able to use a
> string to put the data read from a file into.

Take a look at getline:
std::ifstream is;
std::string str;
std::getline(is, str, '\n');

http://msdn2.microsoft.com/ru-ru/library/3ah895zy(VS.80).aspx

Tom
Andy - 08 Feb 2007 23:28 GMT
> > However, when reading data from a file, I don't seem to be able to use a
> > string to put the data read from a file into.
[quoted text clipped - 7 lines]
>
> Tom

This worked perfectly, thank you very much. =)
- Andy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.