473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

File Access and variable usage/manipulation

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.
Feb 8 '07 #1
2 1129
Andy wrote:
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/lib...zy(VS.80).aspx

Tom
Feb 8 '07 #2
"Tamas Demjen" wrote:
Andy wrote:
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/lib...zy(VS.80).aspx

Tom
This worked perfectly, thank you very much. =)
- Andy
Feb 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: opt_inf_env | last post by:
Hello, I would like to solve the following problem. On the server side I have a file with a sequence of natural numbers (1, 2, 3, 4, 5, ...., n). Each user, after some action, adds new number...
9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
2
by: Count Dracula | last post by:
Is there a way to write a c++ program that will print out the last few lines of a file without reading the whole file? The implementations of 'tail' I have seen all appear to be system dependent....
23
by: Lamberti Fabrizio | last post by:
Hi all, I've to access to a network file from an asp pages. I've red a lot of things on old posts and on Microsoft article but I can't still solve my problem. I've got two server inside the...
15
by: James | last post by:
Hi, I am finding it increasingly difficult to name my variables. I am not able to think in the right way. Expert C programmers please Help. Regards,
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
43
by: ZillionDollarSadist | last post by:
Hello, I'm working at a simple Access '97 + VB4 application, and I ran into a terrible problem: something I never modified now gives me a totally unwanted "Invalid use of null" error. It happens...
4
by: magix | last post by:
Dear Guru, I'm not so good in file manipulation, but would like to seek for help here. I have following basic code of command line argument as starting point (the code below output the...
1
by: pbd22 | last post by:
hi. i have been posting this here and elsewhere a lot and can't seem to get resolution on this problem. i have been trying to upload files using a hidden iframe to a asp.net/vb.net form. the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.