F
Felix85
here is my code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class command {
public:
static void tokenizer(string str, vector<string>& words, string
delimiter){
string::size_type pos1 = 0;
string::size_type pos2 = str.find_first_of(delimiter);
words.push_back(str.substr(pos1 ,pos2 - pos1));
pos1 = pos2 + 1;
while(pos2 <= str.length()){
pos2 = str.find_first_of(delimiter, pos1);
if(pos2 > str.length()){
pos2 = str.length();
}
words.push_back(str.substr(pos1 ,pos2 - pos1));
pos1 = pos2 + 1;
pos2 += 1;
}
}
static void getCommand(){
string c;
cin >> c;
tokenizer(c, com, " ");
if(com.size() == 1){
cout << com[1] << "\n";
} else if(com.size() == 2){
cout << com[1] << "\n" << com[2] << "\n";
} else { cout << "invalid command!\n"; }
}
private:
static vector<string> com;
};
int main()
{
command::getCommand();
return 0;
}
Here is the error I get when I compile:
/tmp/ccNSmcoY.o: In function `command::getCommand()':
command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0x70): undefined
reference to `command::com'
command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0xeb): undefined
reference to `command::com'
command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0x104):
undefined reference to `command::com'
command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0x135):
undefined reference to `command::com'
command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0x14e):
undefined reference to `command::com'
/tmp/ccNSmcoY.o:command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0x165):
more undefined references to `command::com' follow
collect2: ld returned 1 exit status
If anyone can find something please let me know. thanks in advance.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class command {
public:
static void tokenizer(string str, vector<string>& words, string
delimiter){
string::size_type pos1 = 0;
string::size_type pos2 = str.find_first_of(delimiter);
words.push_back(str.substr(pos1 ,pos2 - pos1));
pos1 = pos2 + 1;
while(pos2 <= str.length()){
pos2 = str.find_first_of(delimiter, pos1);
if(pos2 > str.length()){
pos2 = str.length();
}
words.push_back(str.substr(pos1 ,pos2 - pos1));
pos1 = pos2 + 1;
pos2 += 1;
}
}
static void getCommand(){
string c;
cin >> c;
tokenizer(c, com, " ");
if(com.size() == 1){
cout << com[1] << "\n";
} else if(com.size() == 2){
cout << com[1] << "\n" << com[2] << "\n";
} else { cout << "invalid command!\n"; }
}
private:
static vector<string> com;
};
int main()
{
command::getCommand();
return 0;
}
Here is the error I get when I compile:
/tmp/ccNSmcoY.o: In function `command::getCommand()':
command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0x70): undefined
reference to `command::com'
command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0xeb): undefined
reference to `command::com'
command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0x104):
undefined reference to `command::com'
command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0x135):
undefined reference to `command::com'
command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0x14e):
undefined reference to `command::com'
/tmp/ccNSmcoY.o:command.cpp.gnu.linkonce.t._ZN7command10getCommandEv+0x165):
more undefined references to `command::com' follow
collect2: ld returned 1 exit status
If anyone can find something please let me know. thanks in advance.