//Populate vectors
#include "Header.h"
bool populateVectors( stVector &c, stVector &m )
{
//Create an ifstream.
std::ifstream iFile;
iFile.open( "ttmc.dat", std::ios::binary );
//Create a std::string to hold file data
std::string input;
if( iFile.is_open() )
{
//Ignore the first line in the file.
std::getline( iFile, input, '\n' );
//While it's not the end of file, grab data.
while( iFile.good() )
{
//Get data from file. Up until the [tab] ( Character )
std::getline( iFile, input, '\t' );
//Save the character.
c.push_back( input );
//Get data from file. Up until the [newline] ( Morse code )
std::getline( iFile, input, '\n' );
//Save the morse code.
m.push_back( input );
}
//Close the file after use.
iFile.close();
//Return true, on population completion.
returntrue;
}
else
{
std::cout << "\tError opening file to populate the vectors.\n";
returnfalse;
}
}
Sample file of input:
First line.
A .-
B -...
C -.-.
D -..
So, on line 29, std::getline( iFile, input, '\n' );.
When I look at the result of this, I get the following from each vector index:
.-\r
-...\r
-.-.\r
-..\r
Is there a way to stop this behavior? Or a work around to stop this '\r' appearing? '\n' used to be fine and I'd never even seen '\r' in file use before. Can someone please help with this.
Windows use \r\n to mark a new line. When reading a file in text mode (default) it will automatically convert \r\n to \n. In binary mode it will read the file as it is, without converting anything, so that is why you get the \r.