below is my code which tries to separate a string "key=value" into two subarrays "key" and "value" and here are the errors:
string2StringPair.cc:9:3: error: ‘std’ does not name a type; string2StringPair.cc:10:3: error: ‘std’ does not name a type; string2StringPair.cc:13:12: error: expected initializer before ‘string2StringPair'
#ifndef __PARSE_H_
#define __PARSE_H_
#include "cppstd.hh"
#include <string>
using namespace std;
struct StringPair{
std:string key;
std:string value;
}
StringPair string2StringPair (char* str[]){
std:string x, y;
x = ""; y = "";
for (int i=0;i<str.length();i++){
if str[i]=="="{
for (int j=0;j<i;j++){
x=x+str[j];
}
for (int k=(i+1);k<str.length();k++){
y=y+str[k];
}
break;
}
}
if ((x=="") && (y=="")){
cout<<"ERROR: There is no = in the input string!"<<endl;
}
StringPair tmp;
tmp.key = x;
tmp.value = y;
return tmp;
}
#endif
int main(int argc, char *argv[]){
StringPair pair;
pair.string2StringPair(argv[1]);
cout<<"The pair is "<<pair<<endl;
return 0;
}
would really appreciate if you could help me fix the errors.
When I changed to
std::string key;
std::string value;
There was no more "std" error. Why??
Why is an initializer expected before string2StringPair? I though I already had one: StringPair?