无论我使用getline函数,我在“error:expected primary-expression before”,“token”在我的代码中。 我看了一些在ifstreams上使用getline的人的例子,我想也许我必须在调用函数之前加上“std ::”(不确定会做什么?),但这也不起作用。C++错误“'”标记之前的预期主表达式(在ifstream上使用getline?)
这是我的代码的第一位;我假设我所做的任何错误都是一样的。
#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 to hold user data */
ListNode *root;
ListNode *conductor;
root = new ListNode;
conductor = root;
string temp;
//creates and opens filestream to password file
ifstream psswdFile ("example.txt");
if(psswdFile.is_open()){
//we assume there is at least one line, and initialize the head of
//the list
std::getline(psswdFile&, (conductor->user)&, ':');
std::getline(psswdFile&, (conductor->salt)&, ':');
std::getline(psswdFile&, (conductor->encrypted)&);
'std :: getline(psswdFile&,(conductor-> user)&,':');'你能解释一下你在做什么吗? – PaulMcKenzie 2014-12-06 00:51:38
你不需要'&'在C++中通过引用传递参数。只要写'std :: getline(pswdFile,[...]' – 2014-12-06 00:54:12