Author Topic: Does anyone know C++?  (Read 882 times)

0 Members and 1 Guest are viewing this topic.

Offline zxlkho

  • Official Dream Theater Hater.
  • DTF.org Member
  • *
  • Posts: 7666
  • Gender: Male
Does anyone know C++?
« on: October 19, 2011, 03:41:46 PM »
I could really use some help right now. I'll post my code and question if anyone thinks they can help. It involves relatively simple file input and output (I just started learning the language this semester).
I AM A GUY
You're a fucking stupid bitch.
Orion....that's the one with a bunch of power chords and boringly harsh vocals, isn't it?

Offline zxlkho

  • Official Dream Theater Hater.
  • DTF.org Member
  • *
  • Posts: 7666
  • Gender: Male
Re: Does anyone know C++?
« Reply #1 on: October 19, 2011, 03:57:08 PM »
Alright I'll just throw this here in case anyone knows.

Quote
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
float total, median, mean, line;
unsigned int linecount;
ifstream inFile;
string infilename = argv[1];
string outfilename = argv[2];
inFile.open(infilename);
float sortnum[100];
if (inFile.fail())
   {
   cout << "\nThe file was not successfully opened." << endl;
   return EXIT_FAILURE;
   }
linecount = 0;
while (!inFile.eof()) //reads file into the array
   {
   getline(inFile, line);
   if(line.empty()) continue;
   sortnum[linecount] = line;
   linecount += 1;
   }

return 0;
}

This isn't the entire program(hence the variables that are declared and not used), just the part where I'm inputting the numbers from the file into an array. Basically it's supposed to read exactly 100 value from a file where there's one value on each line, and put it into an array. Later I have to sort the numbers to put them in order and output them into another file, but that isn't the part I'm having trouble with.

The compiler gives me multiple ridiculous errors with the line "getline(inFile, line);" It says it doesn't recognize "getline, but I thought that was included under <string>.
Also, it has an error for "line.empty()", which should be included under <string> as well, right?
This is what the compiler says:


I could really use some help with this. Please Please Please.
I AM A GUY
You're a fucking stupid bitch.
Orion....that's the one with a bunch of power chords and boringly harsh vocals, isn't it?

Offline Ultimetalhead

  • The Mighty Masturbator
  • DTF.org Alumni
  • ****
  • Posts: 7029
  • Gender: Male
  • .ay rof dab s'ti dna...
Re: Does anyone know C++?
« Reply #2 on: October 19, 2011, 04:02:17 PM »
Poop.
Orion....that's the one with a bunch of power chords and boringly harsh vocals, isn't it?
LOOK AT THIS AWESOME SHIT AHHHHHH

Offline zxlkho

  • Official Dream Theater Hater.
  • DTF.org Member
  • *
  • Posts: 7666
  • Gender: Male
Re: Does anyone know C++?
« Reply #3 on: October 19, 2011, 04:05:57 PM »
thanks d00d
I AM A GUY
You're a fucking stupid bitch.
Orion....that's the one with a bunch of power chords and boringly harsh vocals, isn't it?

Offline Ultimetalhead

  • The Mighty Masturbator
  • DTF.org Alumni
  • ****
  • Posts: 7029
  • Gender: Male
  • .ay rof dab s'ti dna...
Re: Does anyone know C++?
« Reply #4 on: October 19, 2011, 04:13:26 PM »
You are welcome.

Orion....that's the one with a bunch of power chords and boringly harsh vocals, isn't it?
LOOK AT THIS AWESOME SHIT AHHHHHH

Offline nikatapi

  • Posts: 1640
  • Gender: Male
Re: Does anyone know C++?
« Reply #5 on: October 19, 2011, 04:17:25 PM »
Maybe try to use: <include string.h>
i dont know if it makes any difference though, i've only programmed in java and c.

Offline AcidLameLTE

  • Nae deal pal
  • DTF.org Alumni
  • ****
  • Posts: 11134
  • Gender: Male
Re: Does anyone know C++?
« Reply #6 on: October 19, 2011, 04:18:41 PM »
Maybe try to use: <include string.h>
i dont know if it makes any difference though, i've only programmed in java and c.
You don't need to do that.

I'm too tired to read through the code though so I'm going to bed. Good night

Offline Jamesman42

  • There you'll find me
  • DT.net Member
  • ***
  • Posts: 21817
  • Spiral OUT
Re: Does anyone know C++?
« Reply #7 on: October 19, 2011, 04:22:24 PM »
Zhklolk, I hope you get the help you need in this thread from people knowledgeable in the subject matter. :) :) :)

Offline Dr. DTVT

  • DTF's resident Mad Scientist
  • DTF.org Alumni
  • ****
  • Posts: 9525
  • Gender: Male
  • What's your favorite planet? Mine's the Sun!
Re: Does anyone know C++?
« Reply #8 on: October 19, 2011, 04:57:52 PM »
I could really use some help right now. I'll post my code and question if anyone thinks they can help. It involves relatively simple file input and output (I just started learning the language this semester).

This is the only subject that has ever completely kicked my ass.  Quantum mechanics makes infinitely more sense than C++ does to me.  Thankfully we have some computer geeks here to counterbalance my science nerdiness.
     

Offline zxlkho

  • Official Dream Theater Hater.
  • DTF.org Member
  • *
  • Posts: 7666
  • Gender: Male
Re: Does anyone know C++?
« Reply #9 on: October 19, 2011, 05:05:04 PM »
I just figured it out thanks to an awesome guy on reddit.

getline() can only be used with a string type, so I changed line to a sting and inserted a new variable nline in the while loop. "nline = atof(line.ctr());" which converts it to a double.
I AM A GUY
You're a fucking stupid bitch.
Orion....that's the one with a bunch of power chords and boringly harsh vocals, isn't it?