string function not working

the following is not working for me , i am getting error "expected ')' before numeric constant"

char line[100];

string lineStr(line,50);

Please show the smallest possible complete program that illustrates your problem.

put your full program please
here is the complete code , the code compiles if i comment out the string lineStr(line,50).
this is AVR GCC btw.
thanks

1
2
3
4
5
6
7
8
9
10
11
12
#define F_CPU 11059200UL

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char line[100]="33,33,33,1024,561,21,21";
int main (void)
{
   string lineStr(line,50);
}
Is this a C or C++ program? It looks like a C program to me.
1
2
3
4
5
6
7
#include <string>

char line[100] = "33,33,33,1024,561,21,21";
int main(void)
{
    std::string lineStr(line, 50);
}
why is my option not working ? i saw many places on web people using that syntax
also with this new code iam getting the following error:

expected expression before ":" token
label 'std' defined but not used

this is AVR GCC which is a C++ for micro contollers.
Last edited on
Based on http://www.atmel.com/webdoc/AVRLibcReferenceManual/FAQ_1faq_cplusplus.html

none of the C++ related standard functions, classes, and template classes are available.

So, you can't use strings unless you find or build a non-standard string class.
but string.h comes with AVRGCC so what is it containing if not string functions?
also found this on web, apparently all the string functions do exist in AVR GCC?

http://www.nongnu.org/avr-libc/user-manual/group__avr__string.html
The <string.h> include file is a C header not a C++ header. You can use character strings but not C++ std::strings. I would suggest that you stick with C with this compiler.
ok thanks !
please take a look at my other post , can you suggest the C solution for what i want to try?
Topic archived. No new replies allowed.