Click here to Skip to main content
14,265,784 members
Rate this:
Please Sign up or sign in to vote.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <map>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

int main() {
	
	string line;
	vector<string> def;
	map<string, string>;
	ifstream input;

	if (!input) {
		cout << "File not opened!";
		exit(1);
	}

	input.open("Data.CS.SFSU");

	while (!input.eof()) {
			
		getline(input, line, '|');
		def.pop_back(line);//too many arguments in a function call (red line on "line")
	}

	input.close();

	return 0;
}


What I have tried:

I've tried googling but couldn't find a solution close enough to my problem.
Posted
Updated 4 days ago
v3
Comments
KarstenK 3 days ago
   
didnt you use the debugger what was going on???
Rate this:
Please Sign up or sign in to vote.

Solution 1

Quote:
def.pop_back(line);//too many arguments in a function call (red line on "line")
The correct method is push_back, see vector::push_back[^].
The pop_back method is used for deleting the last element of the vector.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

That should be def.push_back(line). pop_back() deletes the last element of the vector. See vector::pop_back - C++ Reference[^]
Additionally map<string,string>; should be generating a compiler error, as it does not declare anything.
   
Comments
Stefan_Lang 3 days ago
   
Any statement looking like some type and a semicolon will be interpreted as a forward declaration, so map<string,string>; is valid C++, albeit not very useful.
k5054 3 days ago
   
Interesting -- g++ says error: declaration does not declare anything [-fpermissive], clang OTOH says warning: declaration does not declare anything [-Wmissing-declarations]. I wouldn't call it a forward declaration, though, as it doesn't provide anything useful at all.
Stefan_Lang yesterday
   
Interesting indeed: Visual STudio entirely ignores it, even with -wall !

TBH I've always *thought* this is the syntax for forward declaring a templated type, but you are right, online gdb also declares it an error: https://www.onlinegdb.com/online_c++_compiler
Rate this:
Please Sign up or sign in to vote.

Solution 3

Looks like your code have more than 1 problem:
This should be better:
input.open("Data.CS.SFSU");      // 1 open file
if (!input) {                    // 2 check if failed
    cout << "File not opened!";
    exit(1);
}
input.open("Data.CS.SFSU");


Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
Indentation style - Wikipedia[^]

Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 4

Try this :
int main()
{
    std::ifstream input;
    input.open( "Data.CS.SFSU" );

    std::string line;
    std::vector< std::string > def;

    while( ! input.eof() )
    {
        getline( input, line, '|' );
        def.push_back( line );
    }

    input.close();
    return 0;
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100