|
-
February 9th, 2011, 12:45 AM
#1
General issue - new to C++
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?
Thanks in advance.
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <jEshHeader.h>
#include <string>
#include <vector>
using namespace std;
int main (){
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;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|