#How to use getline to get csv and store values into a struct

41 messages · Page 1 of 1 (latest)

gray imp
#

Need help

celest zealotBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

zealous fjord
#
std::string line; 
while(std::getline(stream, line)) {
  auto str = std::stringstream{std::move(line)};
  std::string word; 
  while (std::getline(str, word, ',')) {
    // do stuff with each word 
  }
}
gray imp
#

Im doing it in a function like this:

void gatherData(Data * p, numLines){
    for (int i = 0; i < numLines; i++){
        getLine(input, 80, ',')
    }    
}```
#

where does the getLine store what it gets?

gray imp
#

i dont know what im doing wrong

gray imp
#

please help this is what i have now

zealous fjord
gray imp
#

why wont this work

zealous fjord
gray imp
#

please help me

zealous fjord
#

You do realize I can't do anything without the error?

zealous fjord
#

Don't use new in modern C++.

#

Just use a damn vector.

gray imp
zealous fjord
#

It's telling you it's not a pointer.

gray imp
#

new is all i know as of now

zealous fjord
#

Use . not ->

gray imp
#

that wont work either

#

look

zealous fjord
#

And using a new array has been obsolete since 1998.

gray imp
zealous fjord
#

You can't call getline on a char array, use std::string.

gray imp
#

Its a struct though

zealous fjord
#

So?

gray imp
#

so how do i change it to that if its a struct

#

do i need to #include something?

zealous fjord
#

#include <string>

gray imp
zealous fjord
gray imp
#

cstring

zealous fjord
#

Just assign it.

#

Or pass it in the constructor, either way.