Heres my question, we are required to call any text file using the command line, without using the string class #include<string.h>, so i cant use getline(). How are you supposed to do this. Really need help, thanks.
There are two getlines. One for strings and another for character arrays. The getline the link goes to is the one for character arrays. You can use it without the strings library. This one is cin.getline.
Thanks for the tutorial, but i have one more question. Everything compiles but when i try adding the text file, as many different ways that i have written the code it always gives me the declaration syntax error.
so i get
C:\users\username>bcc32 program.cpp text.txt
borland c++ 5.5.1 for win32 copyright <c> 1993, 2000 Borland
program.cpp:
text.txt:
error e2141 add.txt 1: declaration syntax error
***1 errors in compile ***
Ok nevermind i got it, reason was how i was running the program
in the command line shoulda been with the .exe file after starting compiler and then the .txt file.
No what i do is take the data in the text file which should be integers and then add them, after that i pass the sum to the sum.txt file. I realized there was some errors in my code so i fixed it
So in the while loop i would do the sum stuff.
It's ofstream, not fstream. Also, I think that you can just put #include<fstream> instead of including both fstream and iostream. The reason is that if you look at the hierarchy:
Thanks removed iostream, for some reason i always add it. i just have one last problem in my code that i cannot figure out.
In my while loop after i open the input file, i want it to read the file and if it has any characters that are not numbers, so it cannot have any spaces in between numbers without an addition sign in between (valid 1+3+5+6, invalid 1+4 5+7, invalid A+B+3+4) to exit the loop and show an invalid sequence in the output file, if it is valid i want it to do the summation. Here is the code
Thanks im new to this command line stuff, I have one more problem, i have to put some special cases in there like it cannot allow (1+2+A), so it can not allow Letters, and spaces between numbers like this (1+2 5+4) if these happen then i write invalid sequence to the output file. Help please.