Converting char array to string
I'm having the hardest time attempting to convert a char [] into a string. Here's a snippet of the code that I'm trying to work with.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
string Symtablelab[1000];
char line[100];
char label[9];
char * pch;
myFile.getline(line,100,'\n');
if ( line[0] != '\t' && line[0]!=' ')
{
if( pch = strtok(line," \t"))
{
strcpy(label,pch);
Symtablelab[i] = label;
}
}
|
I'd like to take the entire cstring in label and place it in the first element of the Symtablelab array. Is there any way to do this?
Symtablelab[0] = label;
This must help! but sorry for not using labels in this context...
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
stringstream ss;
string test[2];
char test1[6]={'K','w','e','s','i','\0'};
ss<<test1;
ss>>test[1];
cout<<test[1];
}
|
Topic archived. No new replies allowed.