473,406 Members | 2,345 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,406 software developers and data experts.

How to input?

i have a file which contains many words as a list.. like this:

Midhun
wonderful
excellent
handsome
interesting

how can i initialise each of these words into a string? I'd like to use
a vector of strings to do few operations on these words.

Jul 23 '05 #1
3 1160
> how can i initialise each of these words into a string? I'd like to use
a vector of strings to do few operations on these words.


std::ifstream
std::string
std::vector
std::getline

regards,
ben
Jul 23 '05 #2
here's what i tried.. it is giving me error.. I'm a novice programmer..
any help with the getline?

#include <iostream>
#include <fstream>
#include <vector>
#include <String>
using namespace std;
void main(){
string rhyme_line;
vector <string> rhymefact;
ifstream database("base.rfy");
cout<<"Database is loading...\n";
while (database){
database.getline(rhyme_line,'\n');
if (rhyme_line=="STOPSTOP")
break;
rhymefact.push_back(rhyme_line);
}
system("cls");
cout<<"Database loaded\n";
/* i've to write more codes here once the above part is done correctly
*/
}

the file name is base.rfy and the delimiter of words is '\n'....

Jul 23 '05 #3
Midhun K Menon wrote:
here's what i tried.. it is giving me error.. I'm a novice programmer..
any help with the getline?

#include <iostream>
#include <fstream>
#include <vector>
#include <String>
Make this

#include <string>

with a lowercase 's'.
using namespace std;
Not recommended. At least, put it in function scope.
void main(){
main() returns an int, always.

int main()
{
using namespace std;
string rhyme_line;
vector <string> rhymefact;
ifstream database("base.rfy");
You should check whether the file was correctly opened:

if (!database)
// error..
cout<<"Database is loading...\n";
while (database){
database.getline(rhyme_line,'\n');
std::istream::getline() works on c-style strings, not on std::string.
You should use std::getline():

getline(database, rhyme_line);

and in this case, the delimiter is redundant.
if (rhyme_line=="STOPSTOP")
break;
rhymefact.push_back(rhyme_line);
}
system("cls");
Non portable. On my system, "cls" is the command to reboot the
computer, not to clear the screen. Hopefully I didn't run your program.
cout<<"Database loaded\n";
/* i've to write more codes here once the above part is done correctly
*/
}

the file name is base.rfy and the delimiter of words is '\n'....

Jonathan

Jul 23 '05 #4

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

Similar topics

0
by: gotcha | last post by:
I have a little code to add multiple items to a shopping cart based page. This code works perfect, but it adds all of the info to the same input fields every time it loops. I need it to change...
3
by: david | last post by:
HI! Im trying to make "HTML form" into automatic. 1. If I get 18 numbers like: A B C D E F . . . . 2. How can I put those 18 numbers automatically into 6 numbers format like: A B C D E F
2
by: SophistiCat | last post by:
Hi, I am working on a computational program that has to read a number of parameters (~50) from an input file. The program contains a single class hierarchy with about a dozen member-classes or...
2
by: Cranky | last post by:
Ok, here is my scenario: I need to input numbers using my handheld IPAQ. I figured out how to create an online numeric keypad for inputting numbers into an input field, what I need to know is how...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
3
by: cbradio | last post by:
Hi, I am having trouble developing a form in a restricted environment. My sample code is found below my message (sorry I don't have a URL). Basically, without a doctype, the form displays properly...
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,...
13
by: cront | last post by:
I have a problem to work on: we will ask user to input anything and we will put that back onto the standard output with all set of brackets removed. We will not remove any single bracket e.g. ...
1
by: tcertain | last post by:
I am totally duh at javascript although I have 2 books trying to learn it. I am trying to add values to a form and have a calculate total at end. this is my form script. I have hours at end of...
1
by: printline | last post by:
Hello All I'm quite new to xml vs. PHP, so i hope someone can help with an issue i have been struggeling with. I have an html form, that when submitted, it should create an xml file, and save...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
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,...
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
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.