So far I have it so that I can open up a file. From there I'm trying to go through the each word of the file and if it starts with an A, I want to throw it into a linked list for words starting with A. So essentially I want to take word #1, if it starts with A or a, throw it in a A linked list. then move onto word #2.... Any suggestions would be extremely helpful. here is the code I have so far....
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string fileName;
cout << "Enter the name of the file: ";
cin >> fileName;
ifstream ifs;
ifs.open(fileName.c_str());
if (!ifs.is_open())
{
cout << "That file does not exist" << endl;
system("pause");
}
return 0;
}
7 3303 sicarie 4,677
Recognized Expert Moderator Specialist
You need to declare or implement your linkedlist, get the input, get an individual word, store that, check to see if the first letter is a, if so put it in list, if not, get next word, when words are done, get more input, done while !eof
You need to declare or implement your linkedlist, get the input, get an individual word, store that, check to see if the first letter is a, if so put it in list, if not, get next word, when words are done, get more input, done while !eof
My main concern is that I'm unsure of how to go about getting the first word... I've been looking for some kind of tutorial or write up on how to go about doing it, but haven't been to successful.
sicarie 4,677
Recognized Expert Moderator Specialist
My main concern is that I'm unsure of how to go about getting the first word... I've been looking for some kind of tutorial or write up on how to go about doing it, but haven't been to successful.
You have your ifs declared, you can use >> to read in from it, or getline, or a number of methods. A site I frequently link to is cplusplus.com, as they have pretty good tutorials (IMHO).
You have your ifs declared, you can use >> to read in from it, or getline, or a number of methods. A site I frequently link to is cplusplus.com, as they have pretty good tutorials (IMHO).
alright thank you.. I'll check that website out now
i ended up figuring out how to read the words in word by word... but i'm trying to have it so that if the word starts with a " (quote) that it will look at the next letter in the character array... but I can't get it to take " in single quotes for the comparison. Here is my code... I think there is some kind of \ that will stop it from reading it as a quote and use it as an actual character but I can't remember what it is... - else if(character[0] == '"')
i ended up figuring out how to read the words in word by word... but i'm trying to have it so that if the word starts with a " (quote) that it will look at the next letter in the character array... but I can't get it to take " in single quotes for the comparison. Here is my code... I think there is some kind of \ that will stop it from reading it as a quote and use it as an actual character but I can't remember what it is... - else if(character[0] == '"')
nvrmind.. it was the backslash i'm not sure as to why it didnt work earlier.
sicarie 4,677
Recognized Expert Moderator Specialist
Glad you figured it out!
If you have any more trouble, feel free to post again.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ruben |
last post by:
Hello.
I am trying to read a small text file using the readline statement. I
can only read the first 2 records from the file. It stops at the blank
lines or at lines with only spaces. I have a...
|
by: cricfan |
last post by:
I'm parsing a text file to extract word definitions. For example the
input text file contains the following content:
di.va.gate \'di_--v*-.ga_-t\ vb
pas.sim \'pas-*m\ adv : here and there :...
|
by: H |
last post by:
Now, I'm here with another newbie question ....
I want to read a text file, string by string (to do some things with some
words etc etc), but I can't seem to find a way to do this String by...
|
by: kulet |
last post by:
"2nd post as i noone could do it"
Hi guys! Got stuck with this..
I have a chunks of text separated with blanc line. All I need is to
take every last 3 lines of that text before the blanc line...
|
by: RallyDSM |
last post by:
Hello,
I'm currently trying to read a .CSV file and get all the data into an
array so I can work with it in the program.
Here is what I currently have.
Private Sub IntializeData()
Dim AL...
| |
by: bowlderster |
last post by:
Hello, all.
This is the text file named test.txt.
1041 1467 7334 9500 2169 7724 3478 3358 9962 7464
6705 2145 6281 8827 1961 1491 3995 3942 5827 6436
6391 6604 4902 1153 1292 4382 9421 1716...
|
by: summy |
last post by:
Write a program includes ALL the features:
1.Read the specify file sample.txt and then print the contents of the file on screen.
2.Print each lines of the file in reversed order on screen. ...
|
by: alivip |
last post by:
Is python provide search in parent folder contain sub folders and files
for example folder name is cars and sub file is Toyota,Honda and BMW and Toyota contain file name camry and file name corola,...
|
by: No Signal X |
last post by:
hello
i'm having a problem in reading a text file line by line with splitting words, counting the number of lines & words and saving the position of each word
i've started with this :
public...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
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,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |