473,322 Members | 1,614 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,322 software developers and data experts.

Input pattern and read text

Hi again,
Ok, i've solved my own problem, but now i have a tiny problem that i can't
seem to solve. :( here's my code:
#include <fstream>
#include <string>
#include <iostream>

using namespace std;

int main()
{ string pattern;
ifstream myFile("data.txt");

cout << "Enter the item you are searching for: ";
cin >> pattern;

if (getline(myFile, pattern))
cout << "The pattern was found " << endl;
else
cout << "The pattern was not found in the list\n";

}

my code complied correctly. my problem is, when it runs, the window
appears and then disappears really quickly. i was wondering how i could
solve that?? is there something wrong with my code?

Jul 22 '05 #1
5 1384
kittykat wrote:
Ok, i've solved my own problem,
Actually, I doubt that you did: the code you created does not search
for a pattern in any way!
if (getline(myFile, pattern))
The above line just reads a line and stores it in the variable
'pattern', overwriting its contents. It does not care about the
contents prior to the statement.
my code complied correctly. my problem is, when it runs, the window
appears and then disappears really quickly.


Start your program from the command line! If you insist in starting
it from some IDE, you probably have to delay the termination of the
program, e.g. making the use hit return:

std::string dummy;
std::getline(std::cin, dummy);
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

Jul 22 '05 #2
thanx for pointing that out. could you explain this bit please:
"Start your program from the command line! If you insist in starting it
from some IDE, you probably have to delay the termination of the program".
I dont understand what an IDE is.

Jul 22 '05 #3
kittykat wrote:
thanx for pointing that out. could you explain this bit please:
"Start your program from the command line! If you insist in starting it
from some IDE, you probably have to delay the termination of the program".
I dont understand what an IDE is.

IDE means integrated development environment. For example, Eclipse and
Visual Studio are IDEs. What's being integrated? The compiler, linker,
and various other tools that help you build your program. One thing the
IDE does is allow you to press a button to run your program instead of
manually running it from a command line by typing its name. In your
case, you probably want to do the latter so you can see all the output.
Jul 22 '05 #4
I'm using Dev-C++, so how shall i run my program manually. what shall i
use? and what commands shall i use? i'm a beginner in C++, and have been
thrown in the deep end, so forgive me if my questions are really basic!

Jul 22 '05 #5
kittykat wrote:
I'm using Dev-C++, so how shall i run my program manually. what shall i
use? and what commands shall i use? i'm a beginner in C++, and have been
thrown in the deep end, so forgive me if my questions are really basic!

Just go to start menu and click on "Run...". Then type in "cmd" or
"command". At the prompt, type "cd c:\my\program\directory". Then type
"myprogramname". You have to use your own directory name and program
name. Also, if you need further help, I suggest continuing this thread
by posting in the more topical alt.comp.lang.learn.c-c++. This
newsgroup is really only for C++ language-related discussion.
Jul 22 '05 #6

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

Similar topics

5
by: Gregg | last post by:
Hello all, I have been banging my head over a problem that I am having reading a comma seperated file (CSV) that can contain from 1 to 10,000 records. My code snipit is as follows: **Start...
10
by: Aleks Dubinskiy | last post by:
Hi folks, I am well aware of the superiority of using streams and operators << / >> instead of the old-style printf and scanf. However, there is only one obstacle that prevents me from switching...
3
by: kittykat | last post by:
Hi, I was wondering if you could help me. I am writing a program in C++, and the problem is, i have very limited experience in this language. I would like my user to enter a specific pattern, and...
7
by: Generic Usenet Account | last post by:
I am trying to set up a delimiter character string for the input stream such that the delimiter string is "skipped over" in the input stream. Can someone suggest how to do this with some sample...
2
by: Holger | last post by:
I needed a tool for extracting patches from CVS based on the log messages. I.e. we mark our fixes and features with a "Bugdb XYZ" And sometimes you need to move a fix/feature to another branch or...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
19
by: konrad Krupa | last post by:
I'm not expert in Pattern Matching and it would take me a while to come up with the syntax for what I'm trying to do. I hope there are some experts that can help me. I'm trying to match...
2
by: =?Utf-8?B?QWFyb24=?= | last post by:
Hi, I'm having a tricky problem where I want to accept a regular expression pattern from user input but can't get teh escape characters to be prcoessed correctly. If I take the same pattern and...
2
by: vijaykumardahiya | last post by:
Hello Sir, I have a simple Issue but It is not resolve by me i.e input parameter are not store in Ms-Access. I store the input parameter through Standard Action <jsp:useBean>. jsp:useBean call a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.