Outputting strings to a file without single quotes

Hey guys,

I have read in tab delimited information using getline. My code looks like this:

getline(inFile1, books[indexData].item_name, '\t'); //storing in an array of structures

So far as I can tell it works, because when I outfile to a test file I get all the proper values returned. However, when I do output to a file, I get an extra single quote around each data component; i.e. 'book title' instead of book title, the latter being how it was in the original input file. Here is my output code:

outFile << books[indexData].item_name << "'\t'";

I thought after this first course in programming that I had a decent understanding of strings, but I cannot figure out why it is outputting with the single quotes. Perhaps I'm lost somewhere in the subtleties between character arrays and strings. Any explanation as to why this happens would be greatly appreciated. An example of how to get rid of it would be even better. :-)
In C and C++, literal strings live inside of double-quotes. A literal character lives inside of single quotes.

Hence "'\t'" is a string consisting of the three characters:
'
\t
'

To do what you want, just remove the double quotes and send a character instead of a string of three characters:

outFile << books[indexData].item_name << '\t';
Last edited on
That did the trick. I completely missed the fact that I had the tab character in double quotes. Thanks so much! I would have torn the textbook up before figuring out that problem.
Topic archived. No new replies allowed.