Finding '\n' in a text file
Nov 22, 2016 at 1:50am UTC
How would I find the end of the line in a text file. I tried comparing my string variable "pigLatin" to '\n', but that didn't give me the result that I was looking for.
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 30 31 32 33 34 35 36 37 38 39 40 41 42
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
void streamWord(std::ifstream&);
void translateWord(std::string);
int main()
{
std::ifstream inputFile;
inputFile.open("ASSGN8-A.txt" );
streamWord(inputFile);
inputFile.close();
return 0;
}
void streamWord(std::ifstream& streamFile)
{
std::string translateStream;
while (streamFile >> translateStream)
{
translateWord(translateStream);
}
}
void translateWord(std::string pigLatin)
{
std::string temp;
temp = pigLatin.substr(0,1);
pigLatin.erase(0,1);
pigLatin += temp;
pigLatin += "AY" ;
std::cout << pigLatin << " " ;
}
Nov 22, 2016 at 2:07am UTC
but that didn't give me the result that I was looking for.
What is the result you're looking for?
Nov 22, 2016 at 2:15am UTC
Everytime I reach the end of a line in the text file, I would like to make it the end of the line in the output.
Nov 22, 2016 at 3:14am UTC
Is this not sufficient?
std::cout << pigLatin << "\n" ;
Topic archived. No new replies allowed.