class assignment. copy and paste the code below including function call. everyone's worked except mine. they were using macs, I am using a surface book. output ignores the cities. instructor couldn't figure out the problem. infile.ignore issule? config with windows vs mac? I can't figure it out.
I haven't looked at the code seriously, just quickly in passing.
What strikes me is the one thing expected to be a difference between MAC and Windows.
In MAC, which is actually UNIX (and in Linux), the text file lines are terminated with a line feed.
In Windows, they are terminated with a carriage return and then a line feed.
If you took the file from a MAC source, it may be line feed terminated, only.
If THEY took the file from a Windows source, THEY may be getting the impression that every other line is blank.
It's late, I'm not thinking about this all that seriously, but I'd thought I'd play off the point you made about the different operating systems.
They work the same if the source files are as expected for each, but when one takes a file from *nix into Windows, or from Windows into *nix, this one difference can cause issues.
infile.ignore() uses the default values 1 and eof(), so it reads exactly one character, which we are hoping is the '\n' that needs to be removed. This is not a good way to use the function.
infile.ignore(999, '\n') says to read up to 999 chars, but to stop reading once it's read a '\n'.
You are saying it works on Macs, where the common modern line-ending is a simple '\n' (like any *nix). On windows, the line ending is '\r''\n'. I can't test it (easily) right now, but it may be that, even in text mode where '\r''\n' is converted to '\n' on input, infile.ignore() will only read the '\r' and leave the '\n' behind.
tried it. it corrected the math problem but still omitting the cities
1 2 3 4 5 6 7 8 9
is 18.3333
is 0
Before running passByValue value1 = 25
After running passByValue value1 = 25
Before running passByReference value1 = 25
After running passByReference value1 = 26
Process finished with exit code 0
@bigskit13, show all your headers, please. Also, if you show output make sure that it is from the code that you have presented. (Which your last wasn't.)
Also, open a text file with a simple editor (e.g. notepad, if you are using Windows) and type in temps.txt manually. (Don't cut and paste it from elsewhere or download it.) Make sure that there are NO BLANK LINES in your file.
sorry about that gents, could've sworn i did post the code. here it is after simply adding the infile.ignore(999,'\n,); does the math correct but still won't display the temps.txt.
Everything manually entered, checked for spaces etc.
last chance. your code worked beautifully. It has some coding that I haven't been taught yet. I'll try a to debug to figure out why the other code didn't work on my machine when it did for everyone else. I can't seem to make the \r work in any way shape or form. Funny thing is both the TA and instructor couldn't figure it out which means I'm not going to I bet.
@bigskit13,
If that code works then comment out the stringstream lines (which are just simulating an input stream) and uncomment the ifstream line (so that you are returning to the file input). You will also need to reinstate #include <fstream> . At this point you should be dependent on the form of the input file.
The code works fine when reading from file on my Windows 7 PC.
Are you absolutely sure that you have typed a new, clean input file with your editor? And that this is the file being read by the program? Try changing one of the temperatures in that file to make sure that you are reading the particular file that you think you are and not some legacy file that you copied earlier.
again, look your variables through a debugger
if you happen to have an '\r' or another weird character at the end of the string, you may remove it with
1 2
if (city.back() == '\r')
city.pop_back();
> Everything manually entered, checked for spaces etc.
hexdump
uncommented the ifstream ane reinstated fstream and the input file. Also verified that it's reading the correct file by changing the temps. Still won't show the cities.
ne555 that worked! I'm using CLion and couldn't see anything on the debugger. I'm new though so that isn't saying much. can you explain to me what happened or how this works?
if (!infile) {
cout << "File not found\n";
}
while (getline(infile, city))
{
if (city.back() == '\r')
city.pop_back();
infile >> fahren;
infile.ignore( 999, '\n' );
celsius = fahrenToCel(fahren);
cout << "The Celsius temp in " << city << " is " << celsius << endl;
}
The Celsius temp in New York is 18.3333
The Celsius temp in Saint Paul is 0
Before running passByValue value1 = 25
After running passByValue value1 = 25
Before running passByReference value1 = 25
After running passByReference value1 = 26