How do I read text. file and put each word.

struct SSD
{
string word;
int counting = 0;
};
I have this node so if i have about paragraph how do I read the
test and put into string word?
So, lets say
"Brand new word"
output woud be

Brand
new
word

like this?
Last edited on
Ye le guru code... Aur run kar de.. Khataek.....
(Translation: Take this code. It will run)
Place your string in the string variable str.. :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
#include<string>
#include "conio.h"
using namespace std;
struct SSD
{
    string word;
    int counting=0;
};
int main()
{
    SSD obj;
    string str="Brand new word";
    int found=str.find_first_of(" ");
    while(found!=std::string::npos){
        obj.counting++;
        obj.word=str.substr(0,found+1);
        cout<<endl<<obj.word;
        str=str.substr(found+1);
        found=str.find_first_of(" ");
    }
    //For last word
    obj.word=str;
    obj.counting++;
    cout<<endl<<obj.word;
    cout<<endl<<endl<<"No of words present in the string: "<<obj.counting;

}
Last edited on
Topic archived. No new replies allowed.