How to Read a sentence in a .txt file HELP!


** How do i Read a sentence in a .txt file??? My output is just "INeed" now im pretty sure its a getline issue but I cannot figure out how to use it. Anyone that could help me would be awesome

- Thanks**



**This is my data file called File.txt***
I Need Help Guys
Please Help me


**This is my code that isnt working**

#include <iostream>
#include <fstream>
#include <string>

using namespace std;


int main(void) {
string one, two;

ifstream inputFile;

inputFile.open("File.txt");
inputFile >> one;
inputFile >> two;
inputFile.close( );

cout << one;
cout << two;



return 0;



Last edited on
1
2
3
inputFile.open("File.txt");
inputFile >> one;
inputFile >> two;


Your assumption is that >> reads an entire line in this context. It doesn't: it reads a token, just like std::cin.

Use std::getline instead:
1
2
for (std::string line; std::getline(inputfile, line); ) 
  std::cout << line;
Topic archived. No new replies allowed.