Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

Zmienne typu std::string i printf

Ostatnio zmodyfikowano 2011-12-22 21:53
Autor Wiadomość
matoł115
Temat założony przez niniejszego użytkownika
Zmienne typu std::string i printf
» 2011-12-22 21:35:47
Witam! Mam następujący problem:
C/C++
#include <cstdio>
#include <string>
using namespace std;
int main()
{
    int n, k, i, x, y, z;
    scanf( "%d", & n );
    string a[ n ], p;
    for( i = 0; i < n; i++ )
    {
        scanf( "%s", & a[ i ] );
    }
    for( i = 0; i < n; i++ )
    {
        printf( "%s", a[ i ] );
    }
    return 0;
}

Program zwraca: main.cpp:15:21: error: cannot pass objects of non-trivially-copyable type ‘struct std::string’ through ‘...’
Co z tym fantem zrobić?
P-46110
ison
» 2011-12-22 21:53:32
std::string nie możesz wczytać scanfem,
jeśli chodzi o wypisywanie to
printf( "%s", a[ i ].c_str() );
P-46111
« 1 »
  Strona 1 z 1