Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C++
#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 13-Aug-19 13:11pm
v3
Comments
KarstenK 14-Aug-19 13:30pm    
didnt you use the debugger what was going on???

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.
 
Share this answer
 
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.
 
Share this answer
 
Comments
Stefan_Lang 14-Aug-19 4:23am    
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 14-Aug-19 9:36am    
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 16-Aug-19 7:56am    
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
Looks like your code have more than 1 problem:
This should be better:
C++
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[^]
 
Share this answer
 
v2
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;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900