Question

(C++) Need to import the text from a notepad document including a space. I already have...

(C++) Need to import the text from a notepad document including a space. I already have the program, but it is skipping spaces. here is the program and input.

PROGRAM

#include <vector>

#include <iostream>

#include <string.h>

#include <fstream>

#include <cstdlib>

using namespace std;

ifstream in_stream;

string iarray[201];

int s = 0;

void readFromFile() {

in_stream.open("Input7.txt");

if (in_stream.fail()) {

cout << "failed to open. ";

exit(1);

}

while (!in_stream.eof()) {

in_stream >> iarray[s];

s++;

}

}

int main() {

readFromFile();

for (int i = 0; i < s; i=i++) {

cout << iarray[i];

}

return 0;

}

INPUT "Input7.txt"

Th
is
i
s
a
se
nt
en
ce
.

CURRENT OUTPUT

Thisisasentence.

EXPECTED OUTPUT

This is a sentence.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
/* C++ Program - Read and Display File */
                
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
void main()
{
        clrscr();
        ifstream ifile;
        char s[100], fname[20];
        cout<<"Enter file name to read and display its content (like file.txt) : ";
        cin>>fname;
        ifile.open(fname);
        if(!ifile)
        {
                cout<<"Error in opening file..!!";
                getch();
                exit(0);
        }
        while(ifile.eof()==0)
        {
        ifile>>s;
        cout<<s<<" ";
        }
        cout<<"\n";
        ifile.close();
        getch();
}

When the above C++ program is compile and executed, it will produce the following result

/* C++ Program - Read and Display File */ #include-iostream.h> #include-conio.h> #include-string.h> #include-fstream.h> #include-stdlib.h> void main0 clrscr0; ifstream ifile char s[10O], fname[20]; cout<< Enter file name to read and display its content (like file.txt): cin> tname; ifile.open(fname); if(lifile) cout<<Error in opening file getch0; exit(0); !; while(ifile.ecf0-=0) ifile>>S; cout<<s<< cout<<n ifile.close0: getch0; When the above C++program is compile and executed, it will produce the following result

Add a comment
Know the answer?
Add Answer to:
(C++) Need to import the text from a notepad document including a space. I already have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to add something to this C++ program.Additionally I want it to remove 10 words...

    I need to add something to this C++ program.Additionally I want it to remove 10 words from the printing list (Ancient,Europe,Asia,America,North,South,West ,East,Arctica,Greenland) #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int> words);    int main() { // Declaring variables std::map<std::string,int> words;       //defines an input stream for the data file ifstream dataIn;    string infile; cout<<"Please enter a File Name :"; cin>>infile; readFile(infile,words);...

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

  • 1. Suppose the file mystery.txt contains the text below: The whole thing starts about twelve, fourteen...

    1. Suppose the file mystery.txt contains the text below: The whole thing starts about twelve, fourteen or seventeen. #include <iostream> #include <fstream> #include <string> using namespace std; int main() { string word; int i 0; ifstream read("mystery.txt"); while(!read.eof()) { read>>word; if(i < word. length()) cout<<word[i]; i++; } cout<< endl; } seventeen teen

  • Looking for help understanding how this example program flows and works. Can you write comments next...

    Looking for help understanding how this example program flows and works. Can you write comments next to each line of code explaining what it does? Why does it use a switch? why not set the roman numerals as constants instead of a switch? Thank you!! //CPP program for converting roman into integers #include <iostream> #include <fstream> #include<cctype> #include<cstdlib> #include<string.h> using namespace std; int value(char roman) { switch(roman) { case 'I':return 1; case 'V':return 5; case 'X':return 10; case 'L':return 50;...

  • C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one...

    C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one file, and output the result to another file. But i am confused about how to remove whitespace. i need to make a function to do it. It should use string, anyone can help me ? here is my code. #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> using namespace std; void IsFileName(string filename); int main(int argc, char const *argv[]) { string inputfileName = argv[1];...

  • estion 3 1. Suppose the file mystery.txt contains the text below: The whole thing starts about...

    estion 3 1. Suppose the file mystery.txt contains the text below: The whole thing starts about twelve, fourteen or seventeen. #include <iostream> #include <fstream> #include <string> using namespace std; int main() { string word; int i = 0; ifstream read("mystery.txt"); while(!read.eof()) { read>>word; if(i < word.length()) cout<<word[i]; i++; } cout<< endl; 3 seventeen Thirteen fourteen twelve A Moving to the next question prevents changes to this answer. 29

  • I need help debugging this C++ prgram. What Am i doing wrong? //******************************************************** // This program...

    I need help debugging this C++ prgram. What Am i doing wrong? //******************************************************** // This program reads two input files whose lines are //ordered by a key data field. This program should merge //these two files, writing an output file that contains //all lines from both files ordered by the same key field. // //********************************************************* #include <iostream> #include<string> #include<fstream> //prototype void mergeTwoFiles (ifstream&,ifstream&, ofstream&); using namespace std; int main() {string inFile1,inFile2,outFile; // input and output files ifstream in1; ifstream in2;...

  • #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int...

    #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int charcnt(string filename, char ch); int main() { string filename; char ch; int chant = 0; cout << "Enter the name of the input file: "; cin >> filename; cout << endl; cout << "Enter a character: "; cin.ignore(); // ignores newline left in stream after previous input statement cin.get(ch); cout << endl; chcnt = charcnt(filename, ch); cout << "# of " «< ch« "'S:...

  • In c++ please How do I get my printVector function to actually print the vector out?...

    In c++ please How do I get my printVector function to actually print the vector out? I was able to fill the vector with the text file of names, but I can't get it to print it out. Please help #include <iostream> #include <string> #include <fstream> #include <algorithm> #include <vector> using namespace std; void openifile(string filename, ifstream &ifile){    ifile.open(filename.c_str(), ios::in);    if (!ifile){ cerr<<"Error opening input file " << filename << "... Exiting Program."<<endl; exit(1); }    } void...

  • Hey, so i am trying to have my program read a text file using a structure...

    Hey, so i am trying to have my program read a text file using a structure but i also want to be able to modify the results(I kinda have this part but it could be better). I cant seem to get it to read the file(all the values come up as 0 and i'm not sure why because in my other program where it wrote to the txt file the values are on the txt file) i copied and pasted...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT