string function not working

Jan 19, 2016 at 4:28pm
the following is not working for me , i am getting error "expected ')' before numeric constant"

char line[100];

string lineStr(line,50);

Jan 19, 2016 at 4:46pm
Please show the smallest possible complete program that illustrates your problem.

Jan 19, 2016 at 4:47pm
put your full program please
Jan 19, 2016 at 5:30pm
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);
}
Jan 19, 2016 at 5:41pm
Is this a C or C++ program? It looks like a C program to me.
Jan 19, 2016 at 5:47pm
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);
}
Jan 19, 2016 at 6:20pm
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 Jan 19, 2016 at 6:24pm
Jan 19, 2016 at 6:34pm
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.
Jan 19, 2016 at 6:39pm
but string.h comes with AVRGCC so what is it containing if not string functions?
Jan 19, 2016 at 6:43pm
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
Jan 19, 2016 at 6:56pm
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.
Jan 19, 2016 at 7:02pm
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.