Question, I've had this same general compile error for everything I've tried to program in C++. I teaching myself C++ for all my classes this semester, having only studied Java so far, and I just feel like I'm missing something. Below is an example of something I'm trying to do.
Disregard all of the #include statements as this is a test class. Basically, I want to just split a string into an array delimited by whitespace, yet I keep getting the following compilation errors:
test.cpp: In function ‘int main()’:
test.cpp:32: error: ‘split’ was not declared in this scope
test.cpp: At global scope:
test.cpp:37: error: expected unqualified-id before ‘[’ token
test.cpp:48: error: ‘arguments’ was not declared in this scope
test.cpp:49: error: expected unqualified-id before ‘for’
test.cpp:49: error: expected constructor, destructor, or type conversion before ‘<=’ token
test.cpp:49: error: expected constructor, destructor, or type conversion before ‘++’ token
test.cpp:53: error: expected unqualified-id before ‘return’
test.cpp:54: error: expected declaration before ‘}’ token jregan@ubuntu:~/Dropbox/code/OS.HW1$
I am most confused by the one that says "‘split’ was not declared in this scope" as it keeps popping up regardless of which class/function that I attempt to compile. What am I doing wrong? (Some help clarifying the others wouldn't hurt either). Am I failing because I am too java-minded?
string str("Hi my name is unaligned and who are you");
string arguments[MAX_ARGS];
split(arguments, str);
}
string[] split(string arguments[], string str){
string buffer;
stringstream ss(str);
int counter = 0;
while (ss >> buffer)
arguments[counter] = buffer;
counter++;
}
// testing whether the arguments were put into the array
int arrSize = sizeof arguments / sizeof(int);
for (int i = 0; i <= arrSize; i++){
cout << arguments[i];
cout << "\n";
}
return arguments;
}
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
Bookmarks