C++ error Expected primary expression before "'" token (using getline on an ifstream?) -
i getting many errors along lines of "error: expected primary-expression before ',' token" wherever using getline function in code. looked @ examples of people using getline on ifstreams, , thought maybe had put "std::" before calling function (not sure though?) didn't work either.
here's first bit of code; i'm assuming whatever error i'm making same throughout.
#include <stdio.h> #include <iostream> #include <fstream> #include <string> using namespace std; struct listnode{ string user; string salt; string encrypted; string password; listnode* next; }; int main(){ /* initializes singly linked list hold user data */ listnode *root; listnode *conductor; root = new listnode; conductor = root; string temp; //creates , opens filestream password file ifstream psswdfile ("example.txt"); if(psswdfile.is_open()){ //we assume there @ least 1 line, , initialize head of //the list std::getline(psswdfile&, (conductor->user)&, ':'); std::getline(psswdfile&, (conductor->salt)&, ':'); std::getline(psswdfile&, (conductor->encrypted)&);
it looks have misunderstood way pass parameter references c++ functions. unlike pointers need obtain address using &
operator, functions take references not need anything: pass assignable expression:
std::getline(psswdfile, conductor->user, ':');
the compiler has forward declaration of function, knows pass whatever passing reference.
Comments
Post a Comment