×

# storing strings help c++ beginner

 0 The problem is concerned with text occurrence and Im having problems with storing inputs. INPUT: abc defghi jkl bag pencil bag notebook OUTPUT: abc 0 defghi jkl bag 1 pencil bag notebook INPUT EXPLAINED: It is to understood that the first word in the input is the "KEYWORD" to be search in a set of strings and the following set of strings are the words where you will search the occurrence of the "KEYWORD". OUTPUT EXPLAINED: The output consists of the "KEYWORD" followed by the number of its occurrence in the set of strings then next line consists of the set of strings. so I was experimenting with this code  string text; string key; while(cin >> key && getline(cin, text, 'n')) { cout << key << endl; cout << text << endl; }  Its just an experimental draft on how to get the words to be placed on the string but it doesn't work. Please suggest a way on how to get strings for that kind of problem. asked 16 Nov '14, 12:57 135●1●6●19 accept rate: 28%

 0 int main() { string key, text; while(cin >> key && cin.get() && getline(cin, text)) { cout << key << endl; cout << text << endl; } return 0; }  answered 06 Dec '14, 16:04 16●1 accept rate: 33%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,901
×348
×193

question asked: 16 Nov '14, 12:57

question was seen: 810 times

last updated: 06 Dec '14, 16:04