Jump to content
  • Advertisement

theBegger

Member
  • Content Count

    23
  • Joined

  • Last visited

Community Reputation

107 Neutral

About theBegger

  • Rank
    Member
  1. ACCIDENTAL EXTRA CODE BOX? #include <iostream> #include <fstream> #include <stdio.h> #include <cstdlib> #include <string> using namespace std; //Global struct struct component { int mant; double exp; }; //Function Prototypes void readCharacters(component& function) //OUT:Data destination { string scientificNotation; cout << "\t\t\tScientific Notation Calculator\n\n"; cout << "Please enter a number in scientific notation.\n"; cout << "For Example: -0.1234E20\n"; getline(cin, scientificNotation, 'E' && 'e'); function.mant = cin.get(); cout << "The mantissa is " << function.mant << endl; cin.ignore(numeric_limits<streamsize>::max(), 'E' && 'e'); cin >> function.exp; cout << function.exp; } int main () { component function; readCharacters(function); return 0; } This program is getting error It was compiling fine before, I don't know what I did :(. It's tiny code, I know.
  2.   ignoreChanged is the python code. I'm not sure why I would google that and research a language I'm not writing in?? Or did you mean something else?
  3. Okay, thanks! Where did you fin the data?? I googled the heck out of it!
  4. Python has  "ignoreChanged:   built in to ignore and skip windows prompt "Reload from disk?" when a file is changed. Is there something like this in C++, or can it be implemented?
  5. theBegger

    Copy merged data to vector?

    I guess I thought that it read all the lines from inputs at once rather than one at a time.
  6. theBegger

    Copy merged data to vector?

    I know I can sort it, but I can't figure out how to send the data from the first two files into an array...that's my big hold up.
  7. theBegger

    Copy merged data to vector?

    Haha yeah. I'm sorry I have literally been awake for two days because of finals and am just trying to finish this project. My brain isn't working to well at this point. I need to merge two files  [done], read each line of each data file (can't use any fancypants shortcuts built into a library to have the program read the entire file)[done], Sort, print to output file.   I wanted to just do some sort of while loop which would read the data from  a file into an array within the loop, but I'm not allowed ;(.
  8. theBegger

    Copy merged data to vector?

    I can see your code is much more efficient. But, I have to call each line one at a time. That's why I was having such a hard time converting to vector because there are certain elements I simply have to keep.
  9. theBegger

    Copy merged data to vector?

    Let me ask the question in another way: What did you want that line to do? So you just have two text files and you want to combine their lines into an output file, but you want to use a vector to write the output sorted. Is that right? Do the files have the same number of lines? (implied by the way you wrote the loop...).   Yes, exactly. They do have equal number of lines. Thanks a million for the example. I'm gonna fool around with this. I find it about a million times easier to learn this language when I'm given an example which is relevant to my problems, because then I see for myself how things work rather than reading in a reference. :)
  10. theBegger

    Copy merged data to vector?

    The code works well, I'm just trying to use the vector class to alphabetize the data on the output .txt   I just edited it so that you can see the code vector-less...aside from the header.   This code lists the data contained in the two input.txt on the single output.txt, but it isn't alphabetized. I thought if I could copy the input data to a vector first, I could use sort, then copy the data to the output.txt.   Is that a bad idea?
  11. theBegger

    Copy merged data to vector?

    Sorry, the commented out lines are my failed attempt at vector. I just didn't want to get rid of them yet...hanging onto the string of faith thinking I'll figure this out :/. I'm really not sure which constructor I even should use...I've never dealt with vectors before, and we haven't studied them yet.
  12. I'm having trouble figuring out how to copy the data from the two txt files into a vector. I'm trying to do this so I can use vectors sort function for alphabetizing. With the way I've tried to write the code, I keep getting Thanks #include <algorithm> #include <iostream> #include <fstream> #include <cstdlib> #include <vector> #include <string> using namespace std; #define theAdopted "The Adopted.txt" //His family #define theOriginals "The Originals.txt" //Her family #define theBigPicture "The Big Picture.txt" //Our family //Function Prototypes class KeepRunning { //Prototype needed to keep console from closing. public: ~KeepRunning() { cin.get();}}; //Copies text int copyLine(ifstream&, ifstream&, ofstream&); int main() { KeepRunning kr; ifstream hisFamily("The Adopted.txt"); ifstream herFamily("The Originals.txt"); ofstream ourFamily("The Big Picture.txt"); int SIZE1 = 200, SIZE2 = 200; int insA[SIZE1]; int insB[SIZE2]; int outs[SIZE1 + SIZE2]; int lineCountA = 0; int lineCountB = 0; string lineA; string lineB; //Retreive his family's grades. hisFamily; if(hisFamily.fail()) { cerr << "ERROR: Cannot open " << theAdopted << ". \n"; return EXIT_FAILURE; } //Retreive her family's grades. herFamily; if(herFamily.fail()) { cerr << "ERROR: Cannot open " << theOriginals << ". \n"; return EXIT_FAILURE; } //Call theBigPicture. ourFamily; if(ourFamily.fail()) { cerr << "ERROR: Cannot open " << theBigPicture << ". \n"; return EXIT_FAILURE; } //Copy data hisFamily to ourFamily. getline(hisFamily, lineA); getline(herFamily, lineB); while(lineA.length() != 0 && lineB.length() != 0) { lineCountA++; lineCountB++; ourFamily << lineA << endl; ourFamily << lineB << endl; getline(hisFamily,lineA); getline(herFamily,lineB); } cout << "Input data mergered to file 'The Big Picture.exe'." << endl; //Close files. hisFamily.close(); herFamily.close(); ourFamily.close(); return 0; } int copyLine (ifstream& hisFamily, ifstream& herFamily, ofstream& ourFamily) { const char NWLN = '\n'; char nextCh; int charCount = 0; //Merge hisFamily.get(nextCh); while ((nextCh != NWLN) && !hisFamily.eof()) { ourFamily.put(nextCh); charCount++; hisFamily.ignore(nextCh); hisFamily.get (nextCh); } if(!hisFamily.eof()) { ourFamily.put(NWLN); charCount++; } return charCount; }
  13. theBegger

    Program can't locate .txt file

    Wow disregard that....I had an extra bracket
  14. theBegger

    Program can't locate .txt file

    I got it to work, but then I started writing again .  I can't figure out why I'm getting this error. It's calling for a declaration where I thought I had already declared things....         The code is mostly the same, except I hadn't ended the while loop in the main function. So when I added a braket to close that loop, I got this pretty little error. #include <iostream> #include <fstream> #include <cstdlib> #include <string> using namespace std; #define theAdopted "The Adopted.txt" //His family #define theOriginals "The Originals.txt" //Her family #define theBigPicture "The Big Picture.txt" //Our family //Function Prototypes class KeepRunning { //Prototype needed to keep console from closing. public: ~KeepRunning() { cin.get();}}; //Copies text int copyLine(ifstream&, ifstream&, ofstream&); int main() { KeepRunning kr; ifstream hisFamily("The Adopted.txt"); ifstream herFamily("The Originals.txt"); ofstream ourFamily("The Big Picture.txt"); int SIZE1 = 200, SIZE2 = 200; int insA[SIZE1]; int insB[SIZE2]; int outs[SIZE1 + SIZE2]; int lineCount; int index1 = 0; int index2 = 0; int A = 0; int B = 0; //Retreive his family's grades. hisFamily; if(hisFamily.fail()) { cerr << "ERROR: Cannot open " << theAdopted << ". \n"; return EXIT_FAILURE; } //Retreive her family's grades. herFamily; if(herFamily.fail()) { cerr << "ERROR: Cannot open " << theOriginals << ". \n"; return EXIT_FAILURE; } //Call theBigPicture. ourFamily; if(ourFamily.fail()) { cerr << "ERROR: Cannot open " << theBigPicture << ". \n"; return EXIT_FAILURE; } //Copy data hisFamily to ourFamily. string line; lineCount = 0; getline(hisFamily, line); while(line.length() != 0) { lineCount++; ourFamily << line << endl; getline(hisFamily,line); } cout << "Input data mergered to file 'The Big Picture.exe'." << endl; //Close files. hisFamily.close(); herFamily.close(); ourFamily.close(); return 0; } int copyLine (ifstream& hisFamily, ifstream& herFamily, ofstream& ourFamily) { const char NWLN = '\n'; char nextCh; int charCount = 0; //Merge hisFamily.get(nextCh); while ((nextCh != NWLN) && !hisFamily.eof()) { ourFamily.put(nextCh); charCount++; hisFamily.ignore(nextCh); hisFamily.get (nextCh); } if(!hisFamily.eof()) { ourFamily.put(NWLN); charCount++; } return charCount; } }
  15. theBegger

    Program can't locate .txt file

    Sorry to be a pain, but the Windows wants to know if I want to each time the program compiles. Is this because I'm not closing the file out?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!